GH102: Add volatile to CRYPTO_memcmp
authorRich Salz <rsalz@akamai.com>
Fri, 29 Jan 2016 17:09:05 +0000 (12:09 -0500)
committerRich Salz <rsalz@openssl.org>
Sat, 30 Jan 2016 19:37:43 +0000 (14:37 -0500)
Can't hurt and seems to prevent problems from some over-aggressive
(LTO?) compilers.

Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/cryptlib.c
include/openssl/crypto.h

index 14a84243c646aee63c46bc3fb051eda586e1717e..9473799a48ac5abfe07d3f85ace12df20d304483 100644 (file)
@@ -465,11 +465,11 @@ void OpenSSLDie(const char *file, int line, const char *assertion)
 #endif
 }
 
-int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len)
+int CRYPTO_memcmp(const volatile void *in_a, const volatile void *in_b, size_t len)
 {
     size_t i;
-    const unsigned char *a = in_a;
-    const unsigned char *b = in_b;
+    const volatile unsigned char *a = in_a;
+    const volatile unsigned char *b = in_b;
     unsigned char x = 0;
 
     for (i = 0; i < len; i++)
index 26f6c79c8ed869ed2a24b5c35551994d93ce3496..024f2c9b728bcd677ecba57fbf1d4eb681057057 100644 (file)
@@ -542,7 +542,7 @@ int OPENSSL_gmtime_diff(int *pday, int *psec,
  * into a defined order as the return value when a != b is undefined, other
  * than to be non-zero.
  */
-int CRYPTO_memcmp(const void *a, const void *b, size_t len);
+int CRYPTO_memcmp(const volatile void *a, const volatile void *b, size_t len);
 
 /* BEGIN ERROR CODES */
 /*