Closed
Conversation
If Curl_uint32_tbl_count() at some future point actually can return UINT_MAX, this fixes the math to not wrap.
There was a problem hiding this comment.
Pull request overview
Adjusts curl_multi_get_handles() handle-count arithmetic to avoid 32-bit wrap when sizing the returned handle array.
Changes:
- Change local
counttype fromunsigned inttosize_tincurl_multi_get_handles(). - Use
count + 1with a wider type for the allocation sizing expression.
Comments suppressed due to low confidence (1)
lib/multi.c:3732
iremainsunsigned intwhilecountis nowsize_t. To keep types consistent with the allocated array size and avoid any potential truncation/overflow ifcountcan exceedUINT_MAX, consider makingiasize_tas well (and adjust related asserts accordingly).
unsigned int i = 0;
uint32_t mid;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3728
to
3730
| size_t count = Curl_uint32_tbl_count(&multi->xfers); | ||
| CURL **a = curlx_malloc(sizeof(struct Curl_easy *) * (count + 1)); | ||
| if(a) { |
There was a problem hiding this comment.
count is now size_t, but the allocation size expression sizeof(struct Curl_easy *) * (count + 1) can still overflow/wrap on 32-bit when count is large (e.g. UINT32_MAX from Curl_uint32_tbl_count() equals SIZE_MAX). Consider adding an explicit overflow check (for both (count + 1) and the multiplication) and returning NULL on overflow to avoid undersized allocations and potential out-of-bounds writes.
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.
If Curl_uint32_tbl_count() at some future point actually can return UINT_MAX, this fixes the math to not wrap.