-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential UB in secp256k1_der_parse_integer? #876
Comments
Edit: you're right, this is technically UB. You can't pass pointers to one-past-the-end of an array to memcpy. |
@sipa I'm not sure how you came to your conclusion:
The pointer being passed here is both a valid value, and all address computations and accesses to objects (of which there are none) are valid. By my reading, there is nothing wrong with the code. That said, while don't think there is a need to change anything here, I'm not going to oppose anything. |
I consider all of this language-lawyering with very little impact on real systems, but at least here people argue that it violates the standard: https://stackoverflow.com/questions/29844298/is-it-legal-to-call-memcpy-with-zero-length-on-a-pointer-just-past-the-end-of-an |
The argument in your link seems fair. |
This thread on the musl libc mailing list is also worth reading. Participants include: |
Do we consider
memcpy(ra + 32 - rlen, *sig, rlen)
insecp256k1_der_parse_integer
to be defined in the case ofrlen == 0
?secp256k1/src/ecdsa_impl.h
Lines 102 to 104 in 98dac87
secp256k1/src/ecdsa_impl.h
Line 143 in 98dac87
Nothing high priority of course, but perhaps worth fixing? :)
This code was introduced as part of PR #334 ("Overhaul ECDSA signature parsing: strict DER, compact sigs, tests, lower-S") in 3bb9c44 back in 2015.
The text was updated successfully, but these errors were encountered: