Skip to content

examples/io_uring-udp: compute buffer size and offset in size_t#1589

Open
rootvector2 wants to merge 1 commit into
axboe:masterfrom
rootvector2:udp-buffer-shift-size_t
Open

examples/io_uring-udp: compute buffer size and offset in size_t#1589
rootvector2 wants to merge 1 commit into
axboe:masterfrom
rootvector2:udp-buffer-shift-size_t

Conversation

@rootvector2
Copy link
Copy Markdown
Contributor

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant