Fix possible UB in init_info_strings
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Sun, 13 Nov 2022 20:34:16 +0000 (21:34 +0100)
committerTomas Mraz <tomas@openssl.org>
Thu, 22 Dec 2022 11:06:38 +0000 (12:06 +0100)
"openssl version -c" may create undefined behavior in the shift:

crypto/info.c:42:50: runtime error: left shift of 4275712515
by 32 places cannot be represented in type 'long long int'

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19668)

crypto/info.c

index 589a44a8229b3c727aec222db746ce58dab8419f..3a70b1596d7751c1e28858b3933c1f745ee46a61 100644 (file)
@@ -45,10 +45,10 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings)
 
     BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
                  CPUINFO_PREFIX "OPENSSL_ia32cap=0x%llx:0x%llx",
-                 (long long)OPENSSL_ia32cap_P[0] |
-                 (long long)OPENSSL_ia32cap_P[1] << 32,
-                 (long long)OPENSSL_ia32cap_P[2] |
-                 (long long)OPENSSL_ia32cap_P[3] << 32);
+                 (unsigned long long)OPENSSL_ia32cap_P[0] |
+                 (unsigned long long)OPENSSL_ia32cap_P[1] << 32,
+                 (unsigned long long)OPENSSL_ia32cap_P[2] |
+                 (unsigned long long)OPENSSL_ia32cap_P[3] << 32);
     if ((env = getenv("OPENSSL_ia32cap")) != NULL)
         BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
                      sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),