pkey: fix error check of i2d_DHparams()#1033
Conversation
The first call correcly checks for a value <=0, the second call does not. According to LibreSSL docs [1] the error is <=0. For OpenSSL, we refer to [2] which refers to [3] only states that a value <0 returns an error, but this appears to be a docs inconsistency that does not match reality. Fix this inconsistency for LibreSSL by using the same check. [1] https://man.openbsd.org/d2i_DHparams.3 [2] https://manpages.debian.org/stretch/libssl-doc/i2d_DHparams.3ssl.en.html [3] https://manpages.debian.org/stretch/libssl-doc/d2i_X509.3ssl.en.html
|
Related: #1012 I think we should merge this if the 0-return path is actually reachable from ruby/openssl. If it's currently not, I'd prefer to wait until the conflicting docs are clarified at upstream and then fix the inconsistent checks accordingly. Have you raised this with OpenSSL/LibreSSL people? Their internal usage seems inconsistent as well, for example:
I wasn't aware the man page for It seems this wording was introduced in openssl/openssl#4976 for 1.1.1 and later removed in openssl/openssl#13138 for 3.0.0. Neither PR discussed this detail, so it's unclear whether either change was intentional. From an API design perspective, it would be unusual for a function that encodes opaque data and returns its length to use 0 to indicate an error. A return value of 0 would normally imply a successful call that encoded 0 bytes... though, in this case, a successful output might not be expected to be 0 bytes long. |
The first call correctly checks for a value <=0, the second call does not.
According to LibreSSL docs [1] the error is <=0.
For OpenSSL, we refer to [2] which refers to [3] only states that a value <0 returns an error, but this appears to be a docs inconsistency that does not match reality.
Fix this inconsistency for LibreSSL by using the same check.
[1] https://man.openbsd.org/d2i_DHparams.3
[2] https://manpages.debian.org/stretch/libssl-doc/i2d_DHparams.3ssl.en.html
[3] https://manpages.debian.org/stretch/libssl-doc/d2i_X509.3ssl.en.html
This was found by a hybrid static-dynamic analyser that looks for inconsistent handling of error checks in bindings.