Fixed valgrind complaint due to BN_consttime_swap reading uninitialised data.
authorMatt Caswell <matt@openssl.org>
Thu, 10 Jul 2014 22:47:31 +0000 (23:47 +0100)
committerMatt Caswell <matt@openssl.org>
Sun, 13 Jul 2014 21:17:39 +0000 (22:17 +0100)
This is actually ok for this function, but initialised to zero anyway if
PURIFY defined.

This does have the impact of masking any *real* unitialised data reads in bn though.

Patch based on approach suggested by Rich Salz.

PR#3415

crypto/bn/bn_lib.c

index b1e224bb4dc19bbcfec662057179b8860ea67c05..efa77999ff5148b11d60de93a34bab9793a1cd8f 100644 (file)
@@ -324,6 +324,15 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
                BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE);
                return(NULL);
                }
+#ifdef PURIFY
+       /* Valgrind complains in BN_consttime_swap because we process the whole
+        * array even if it's not initialised yet. This doesn't matter in that
+        * function - what's important is constant time operation (we're not
+        * actually going to use the data)
+       */
+       memset(a, 0, sizeof(BN_ULONG)*words);
+#endif
+
 #if 1
        B=b->d;
        /* Check if the previous number needs to be copied */