libpgagroal: utils.c: fix UB in pgagroal_read_int32() #495
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.