a
isn’t null and optimized VERIFY_CHECK(a != NULL);
out.
This put the dereference after the check
Resolves #643
404@@ -405,6 +405,7 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a,
405 VERIFY_CHECK(0 <= len && len <= 256);
406 VERIFY_CHECK(a != NULL);
407 VERIFY_CHECK(2 <= w && w <= 31);
408+ s = *a;
s
?
When I named this I tried to think of a name that won’t sound alarming but still describe what’s the point. I didn’t try to make this sound like a “vulnerability”. it’s not. It’s so nothing I wasn’t even sure if it’s worth a PR and that’s why I opened an issue first #643
If anyone looking at this PR thought it is a vulnerability it’s my fault. suggestions for a title?
No need to apologize, you did nothing wrong. We want people to treat serious issues seriously, but an unfortunate side effect is that a little extra effort needs to go into not falsely triggering serious issue detection. My comment had a suggestion, “avoid optimizing out a verify_check” which was actually your goal! :) Generally it’s most informative if changes are described “why” first either describe the “how” later (or just leave it to the code itself to describe the “how”).
To add some additional colour which might be useful to you in the future there is actually a fair amount of machinery in the codebase already just to avoid optimizing out VERIFY_CHECKs (and even some ARG_CHECKs): Most of the external interface is annotated with nonnull in order to cause the compiler to warn at compile time on the caller’s code when it can prove that an argument will be null. Unfortunately that annotation is treated like a dereference when compiling the function and will cause null checks to be treated like dead code. As a result, when compiling the library itself those annotations are left out (triggered by SECP256K1_BUILD define).