diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2024-02-08 22:21:55 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2024-04-02 17:47:29 +0200 |
commit | 1fa2bf9b1885d2e87524421fea5041d40149cffa (patch) | |
tree | 8909cbc745290c793055797f18c848efdeb1a33e /crypto/dsa | |
parent | Fix openssl req with -addext subjectAltName=dirName (diff) | |
download | openssl-1fa2bf9b1885d2e87524421fea5041d40149cffa.tar.xz openssl-1fa2bf9b1885d2e87524421fea5041d40149cffa.zip |
Fix handling of NULL sig parameter in ECDSA_sign and similar
The problem is, that it almost works to pass sig=NULL to the
ECDSA_sign, ECDSA_sign_ex and DSA_sign, to compute the necessary
space for the resulting signature.
But since the ECDSA signature is non-deterministic
(except when ECDSA_sign_setup/ECDSA_sign_ex are used)
the resulting length may be different when the API is called again.
This can easily cause random memory corruption.
Several internal APIs had the same issue, but since they are
never called with sig=NULL, it is better to make them return an
error in that case, instead of making the code more complex.
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23529)
Diffstat (limited to 'crypto/dsa')
-rw-r--r-- | crypto/dsa/dsa_sign.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/crypto/dsa/dsa_sign.c b/crypto/dsa/dsa_sign.c index b806e7e655..190aca8ad9 100644 --- a/crypto/dsa/dsa_sign.c +++ b/crypto/dsa/dsa_sign.c @@ -157,6 +157,11 @@ int ossl_dsa_sign_int(int type, const unsigned char *dgst, int dlen, { DSA_SIG *s; + if (sig == NULL) { + *siglen = DSA_size(dsa); + return 1; + } + /* legacy case uses the method table */ if (dsa->libctx == NULL || dsa->meth != DSA_get_default_method()) s = DSA_do_sign(dgst, dlen, dsa); @@ -167,7 +172,7 @@ int ossl_dsa_sign_int(int type, const unsigned char *dgst, int dlen, *siglen = 0; return 0; } - *siglen = i2d_DSA_SIG(s, sig != NULL ? &sig : NULL); + *siglen = i2d_DSA_SIG(s, &sig); DSA_SIG_free(s); return 1; } |