This is a pedantic case of UB.
Spotted in #879.
This is a pedantic case of UB.
Spotted in #879.
This is a pedantic case of UB.
Concept ACK
111 | @@ -112,7 +112,7 @@ static int secp256k1_der_parse_integer(secp256k1_scalar *r, const unsigned char 112 | if (secp256k1_der_read_len(&rlen, sig, sigend) == 0) { 113 | return 0; 114 | } 115 | - if (rlen == 0 || *sig + rlen > sigend) { 116 | + if (rlen == 0 || rlen > (size_t)(sigend - *sig)) {
nit, maybe casting rlen to ptrdiff_t is more "correct" (in the standard purist sense)?
It's UB if that cast to ptrdiff_t overflows, and rlen is attacker-controlled data.
(We have these size_t casts everywhere in the file.)
ACK 9be7b0f08340a063d961547b5d2663405f3fc162
This should be correct because we know that signend is always bigger or equal to *sig, so the result of the subtraction must always yield a positive integer
Concept ACK @practicalswift are you willing to review this in detail?
@real-or-random Sure! Thanks for the ping! :)
cr ACK 9be7b0f08340a063d961547b5d2663405f3fc162
ACK 9be7b0f08340a063d961547b5d2663405f3fc162