Repository navigation
Conversation
|
Yes, return 0 on error is what is documented, pretty clearly. We should fix this now. |
|
That the actual function can return -1 and always has means that this is actually a documentation error in this instance. That it should be consistent and not do so is a separate item. Taking a quick "grep" for return statements in the bn code I think this won't be the only function where a return of neither 0 or 1 is possible. |
|
Okay, so you think we should update the doc. I'm fine with that. |
|
No - just pointing out that the source of truth for what an API does isn't the documentation. Ideally the documentation and the code should match - but when they don't we cannot just automatically assume the documentation is the correct item. We need to look at it. There is only one use of BN_exp in the tree in bntest and it does a <= 0 check for failure. All the BN functions should be consistent - but they are not - and I do think this specific change makes sense to make - but the first check needs to be to see the history of the function and its usage - rather than leaping to must-match-the-doc on the assumption that the documentation is correct. On this specific change I'm +1 for including it as it should be this way - and there is no library code impacted - and the change basically doesn't break anything (we just will never return a -1 error indication and that is okay). So it is a change to an API - but it is a compatible change. |
|
ah, thanks. i agree the 1//0/-1 thing needs to be looked at. i will merge this one. |
Reviewed-by: Tim Hudson <[email protected]> Reviewed-by: Rich Salz <[email protected]> (Merged from #1455)
|
merged with commit 0818dba thanks! |
The return code of
BN_exp,BN_mod_expis documented as 0. However it might return -1 in the cases below which can happen if BN is not correct. This is an issue for example inDSA_generate_keythat relies on that return value.This is actually not a theoretical issue as it happened when I was playing with DSA in PHP openssl ext:
https://github.com/php/php-src/blob/c3c90abb17017af83133f57ec5d7663c0b33fdff/ext/openssl/tests/bug72336.phpt
The problem was that we expect binary value - BN_bin2bn is used on the string (meaning user forgot to call hex2bin). What happened is that
DSA_generate_keyreturned 1 (success) but in fact priv key wasn't generated. Currently I have to do this after porting to 1.1 which is a bit messy.https://github.com/php/php-src/blob/c3c90abb17017af83133f57ec5d7663c0b33fdff/ext/openssl/openssl.c#L4077-L4082
I understand that it might not be good to fix it in 1.0.2 due to BC break but 1.1 would be good IMHO.