You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Undefined behavior in curl_share_setopt() UNSHARE path: bit shift before validation #21224
No undefined behavior. The SHARE path in the same function validates type inside the switch before using it in a bit shift. The UNSHARE path at line 150 evaluates 1 << type before the switch validates the value. When type >= 32, this is UB per the C standard.
UBSan output:
curl_share.c:150:43: runtime error: shift exponent 32 is too large for 32-bit type 'int'
#0 curl_share_setopt /lib/curl_share.c:150
#1 main /test_share_ub.c:47
The fix is to move the bit shift after the switch, matching the SHARE path's validate-then-shift pattern. Not a security issue- type is developer-supplied, not from untrusted input.
Activity
bagder commentedon Apr 5, 2026
The largest type libcurl supports is 7 though, so not a big problem...
share: do bitshifts after the type is checked to be valid
share: do bitshifts after the type is checked to be valid
share: do bitshifts after the type is checked to be valid
share: do bitshifts after the type is checked to be valid