Replace memset with OPENSSL_cleanse()
authorMatt Caswell <matt@openssl.org>
Thu, 30 Apr 2015 13:04:30 +0000 (14:04 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 10 Jun 2015 09:29:31 +0000 (10:29 +0100)
BUF_MEM_free() attempts to cleanse memory using memset immediately prior
to a free. This is at risk of being optimised away by the compiler, so
replace with a call to OPENSSL_cleanse() instead.

With thanks to the Open Crypto Audit Project for reporting this issue.

Reviewed-by: Stephen Henson <steve@openssl.org>
crypto/buffer/buffer.c

index d287e340a2ba5c4337b134b2e157698cde3dd564..eff3e081576c48fb3541c650f1b9fc39ad05383b 100644 (file)
@@ -88,7 +88,7 @@ void BUF_MEM_free(BUF_MEM *a)
         return;
 
     if (a->data != NULL) {
-        memset(a->data, 0, (unsigned int)a->max);
+        OPENSSL_cleanse(a->data, a->max);
         OPENSSL_free(a->data);
     }
     OPENSSL_free(a);