bn2binpad: Use memset as the buffer will be used later
authorTomas Mraz <tomas@openssl.org>
Wed, 8 Dec 2021 17:26:03 +0000 (18:26 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 13 Dec 2021 10:32:39 +0000 (11:32 +0100)
Apparently using OPENSSL_cleanse() confuses the fuzzer so it
makes the buffer to appear uninitialized. And memset can be
safely used here and it is also potentially faster.

Fixes #17237

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/17240)

crypto/bn/bn_lib.c

index 28a3e91679d78ec4df9cb9035132846e39e80e90..d37b89c2a6e64cdb41897f0a7c577c3a5591ec44 100644 (file)
@@ -505,7 +505,8 @@ int bn2binpad(const BIGNUM *a, unsigned char *to, int tolen, endianess_t endiane
     /* Swipe through whole available data and don't give away padded zero. */
     atop = a->dmax * BN_BYTES;
     if (atop == 0) {
-        OPENSSL_cleanse(to, tolen);
+        if (tolen != 0)
+            memset(to, '\0', tolen);
         return tolen;
     }