Repository navigation
fix(libcurl): look up an option id without loading an out-of-range CURLoption - #19946
Conversation
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 3673dfec75:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_curl_Options_testsbuilt cleanly. - CTest (
guest_curl_options):1/1 Test #4628: guest_curl_options ............... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 - Negative control: the tests still pass with the change reverted, so they do not cover it
- Code reading:
- Verified core/libs/prx/libcurl/Export.cpp:1344-1350 avoids undefined enum conversion by accepting std::int32_t guestId and comparing against static_caststd::int32_t(opt->id) rather than casting out-of-range integer values to CURLoption.
- Verified core/libs/prx/libcurl/Export.cpp:1345-1348 table iteration using ::curl_easy_option_next correctly matches libcurl's easygetopt.c implementation, ensuring alias options are skipped via (opt->flags & CURLOT_FLAG_ALIAS) == 0.
- Verified core/libs/prx/libcurl/Export.cpp:1349 safely returns nullptr when no matching non-alias option exists for the requested ID.
- Verified core/libs/prx/libcurl/Export.cpp:1344-1350 adheres to AGENTS.md conventions with zero code comments, thread-safe access to libcurl's static option table, and generic handling across all possible inputs.
- Verified core/libs/prx/libcurl/tests/CurlOptions.cpp:31 passes the invalid option ID 999999 directly as std::int32_t without an explicit enum cast, properly exercising the non-matching lookup path under UBSan.
- Verified integer types and comparisons maintain exact LP64 and LLP64 compatibility with no signed/unsigned mismatch or truncation between guestId and opt->id.
- Note: the AI-assisted checkbox can stay.
Requesting changes for the points above.
|
Thanks for checking. The revert passing on GCC is expected: the bug is an out-of-range On I also pushed AI-assisted: yes. |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against dff43cb9e8:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_curl_Options_testsbuilt cleanly. - CTest (
guest_curl_options):1/1 Test #4628: guest_curl_options ............... Passed 0.00 sec 100% tests passed, 0 tests failed out of 1 - Negative control: the tests still pass with the change reverted, so they do not cover it
- Code reading:
- Verified in core/libs/prx/libcurl/Export.cpp that curl_easy_option_by_id_nid_postfix traverses the options table using ::curl_easy_option_next and compares opt->id as std::int32_t against guestId, eliminating undefined enum conversions for invalid IDs such as 999999.
- Verified that the (opt->flags & CURLOT_FLAG_ALIAS) == 0 condition replicates libcurl's lookup behavior, ensuring canonical primary options like CURLOPT_WRITEDATA are returned rather than preceding alias entries like FILE.
- Verified bounds and pointer safety: opt is checked against nullptr on each loop iteration before member dereferencing, and nullptr is correctly returned when no matching option exists.
- Verified portability across LP64 (Linux) and LLP64 (Windows): casting opt->id to std::int32_t and comparing with guestId avoids signed/unsigned mismatch warnings and width discrepancies across platforms.
- Verified AGENTS.md compliance: no comments were added to core/libs/prx/libcurl/Export.cpp or core/libs/prx/libcurl/tests/CurlOptions.cpp, the commit/PR title uses Conventional Commits, and no extraneous files were added.
- Verified test rigor in core/libs/prx/libcurl/tests/CurlOptions.cpp: explicitly exercises valid option retrieval (CURLOPT_URL), verifies canonical non-alias resolution (CURLOPT_WRITEDATA), and tests negative control rejection on arbitrary out-of-range IDs (999999).
- Note: the AI-assisted checkbox can stay.
Requesting changes for the points above.
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against dff43cb9e8:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_curl_Options_testsbuilt cleanly. - CTest (
guest_curl_options):1/1 Test #4628: guest_curl_options ............... Passed 0.00 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libcurl/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4628: guest_curl_options ............... Passed 0.00 sec 100% tests passed, 0 tests failed out of 1 - Code reading:
- Verified in core/libs/prx/libcurl/Export.cpp that curl_easy_option_by_id_nid_postfix traverses the options table using ::curl_easy_option_next and compares opt->id as std::int32_t against guestId, eliminating undefined enum conversions for invalid IDs such as 999999.
- Verified that the (opt->flags & CURLOT_FLAG_ALIAS) == 0 condition replicates libcurl's lookup behavior, ensuring canonical primary options like CURLOPT_WRITEDATA are returned rather than preceding alias entries like FILE.
- Verified bounds and pointer safety: opt is checked against nullptr on each loop iteration before member dereferencing, and nullptr is correctly returned when no matching option exists.
- Verified portability across LP64 (Linux) and LLP64 (Windows): casting opt->id to std::int32_t and comparing with guestId avoids signed/unsigned mismatch warnings and width discrepancies across platforms.
- Verified AGENTS.md compliance: no comments were added to core/libs/prx/libcurl/Export.cpp or core/libs/prx/libcurl/tests/CurlOptions.cpp, the commit/PR title uses Conventional Commits, and no extraneous files were added.
- Verified test rigor in core/libs/prx/libcurl/tests/CurlOptions.cpp: explicitly exercises valid option retrieval (CURLOPT_URL), verifies canonical non-alias resolution (CURLOPT_WRITEDATA), and tests negative control rejection on arbitrary out-of-range IDs (999999).
Looks Good To Me
What
curl_easy_option_by_id_nid_postfixturns the guest'sstd::int32_tinto aCURLoptionwithstatic_castbefore calling::curl_easy_option_by_id. For an id that is not an option, such as the999999thatguest_curl_optionspasses, the value lies outside the range of the enumeration, so the conversion is undefined behaviour. Clang's-fsanitize=undefinedstops the test there:The export now walks the table with
::curl_easy_option_nextand compares each entry's id with the guest id as an integer, skipping alias entries. That is the same match libcurl 7.81.0'slookupinlib/easygetopt.cperforms, so every id returns the same entry ornullptras before, and no out-of-rangeCURLoptionis ever formed. The test passes999999as the export'sstd::int32_tdirectly instead of casting it toCURLoptionfirst, and now also checks thatCURLOPT_WRITEDATAfindsWRITEDATArather than its aliasFILE. This is the same kind of fix as #17644.Tested
Ubuntu 24.04, Ninja, Release,
main2cebbe43ee. The undefined conversion has no visible effect in an ordinary build, so the negative control for it is Clang's-fsanitize=undefined; the newWRITEDATAcheck is the negative control for the lookup loop itself, because its aliasFILEcomes first in libcurl's table.guest_curl_optionsmain+ this PR's test-DANYPS5_ENABLE_ASAN=ON -fsanitize=undefined -fno-sanitize=vptr,function,halt_on_error=1main+ this PR's testExport.cpp:1345:48: runtime error: load of value 999999, which is not a valid value for type 'const CURLoption'&& (opt->flags & CURLOT_FLAG_ALIAS) == 0WRITEDATAlookup returnsFILEWith this PR all 10
guest_curl*tests pass on both GCC 13.3.0 and the Clang sanitizer build.tools/check_conventions.py --base origin/mainandgit diff --check: clean.tools/pr_overlap.py --branch fix/curl-option-by-id-enum: three open PRs also editExport.cpp(feat(libcurl): implement curl_formget #17661, feat(libcurl): implement curl_formadd #17667, feat(libcurl): implement curl_m[v]fprintf and curl_m[v]printf #18468); none touchcurl_easy_option_by_id_nid_postfixor the test.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)