examples/io_uring-udp: compute buffer size and offset in size_t#1589
Open
rootvector2 wants to merge 1 commit into
Open
examples/io_uring-udp: compute buffer size and offset in size_t#1589rootvector2 wants to merge 1 commit into
rootvector2 wants to merge 1 commit into
Conversation
buffer_size() and get_buffer() shift by ctx->buf_shift, which comes from the -b option (log2 of the buffer size), but evaluate 1U << buf_shift and idx << buf_shift in 32-bit before widening to size_t / a pointer. For a shift >= 32 that is undefined behavior, and even otherwise the result truncates to 32 bits, so buffer_size() returns a wrong value and get_buffer() forms an out-of-range pointer. Building with -fsanitize=undefined and running with -b 40 reports runtime error: shift exponent 40 is too large for 32-bit type and buffer_size() returns 256 instead of 2^40. Do both shifts in size_t. Signed-off-by: rootvector2 <dxbnaveed.k@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
buffer_size() and get_buffer() take their shift count from the -b option but evaluate the shift in 32-bit before widening, so a large value is undefined behavior and otherwise truncates the result. Do both shifts in size_t. Building with -fsanitize=undefined and running with -b 40 flags the old code (shift exponent 40 too large for 32-bit type), and buffer_size() returns 256 instead of 2^40.