Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libpgagroal: utils.c: fix UB in pgagroal_read_int32() #495

Merged
merged 1 commit into from
Jan 18, 2025

Conversation

decarv
Copy link
Contributor

@decarv decarv commented Jan 18, 2025

In pgagroal_read_int32, the byte[i] value is promoted to int32. According to the C spec, if you cannot represent the result in the result type, then that behavior is undefined (6.5.7).

The compiler was able to catch this after recent additions to cmake file, producing the runtime error:

libpgagroal/utils.c:319:38: runtime error: left shift of 166 by 24 places cannot be represented in type 'int'

This issue is fixed by explicitly casting the bytes[i] values to uint32_t.

In pgagroal_read_int32, the byte[i] value is promoted to int32.
According to the C spec, if you cannot represent the result
in the result type, then that behavior is undefined (6.5.7).

This issue is fixed by explicitly casting the bytes[i] values
to uint32_t.

Signed-off-by: Henrique de Carvalho <decarv.henrique@gmail.com>
@jesperpedersen jesperpedersen merged commit 1483d2c into agroal:master Jan 18, 2025
2 checks passed
@jesperpedersen
Copy link
Collaborator

Merged.

Thanks for your contribution !

@jesperpedersen jesperpedersen self-requested a review January 18, 2025 05:49
@jesperpedersen jesperpedersen added the bug Something isn't working label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants