]> git.ipfire.org Git - thirdparty/openssl.git/commit
Fix handling of NULL sig parameter in ECDSA_sign and similar
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Thu, 8 Feb 2024 21:21:55 +0000 (22:21 +0100)
committerTomas Mraz <tomas@openssl.org>
Tue, 2 Apr 2024 15:47:29 +0000 (17:47 +0200)
commit1fa2bf9b1885d2e87524421fea5041d40149cffa
tree8909cbc745290c793055797f18c848efdeb1a33e
parent387418893e45e588d1cbd4222549b5113437c9ab
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)
crypto/dsa/dsa_sign.c
crypto/ec/ecdsa_ossl.c
crypto/sm2/sm2_sign.c
test/dsatest.c
test/ecdsatest.c