]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
s390xcap.c: Avoid copying structure on initialization
authorTomas Mraz <tomas@openssl.org>
Mon, 26 Jun 2023 15:13:30 +0000 (17:13 +0200)
committerPauli <pauli@openssl.org>
Tue, 27 Jun 2023 22:30:44 +0000 (08:30 +1000)
This is problematic on old compilers. It also avoids duplicating
the read-only data.

Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21284)

crypto/s390xcap.c

index 59f0f3ef452a3d9d9848194550988c86928fde1a..1c1db5caafb9670e96d72ee5fea8eda1b9e0230e 100644 (file)
             cap->NAME[1] = ~cap->NAME[1];                               \
     }
 
-#define TOK_CPU(NAME)                                                   \
+#define TOK_CPU_ALIAS(NAME, STRUCT_NAME)                                \
     (sscanf(tok_begin,                                                  \
             " %" STR(LEN) "s %" STR(LEN) "s ",                          \
             tok[0], tok[1]) == 1                                        \
      && !strcmp(tok[0], #NAME)) {                                       \
-            memcpy(cap, &NAME, sizeof(*cap));                           \
+            memcpy(cap, &STRUCT_NAME, sizeof(*cap));                    \
     }
 
+#define TOK_CPU(NAME) TOK_CPU_ALIAS(NAME, NAME)
+
 #ifndef OSSL_IMPLEMENT_GETAUXVAL
 static sigjmp_buf ill_jmp;
 static void ill_handler(int sig)
@@ -672,9 +674,8 @@ static int parse_env(struct OPENSSL_s390xcap_st *cap)
 
     /*-
      * z16 (2022) - z/Architecture POP
-     * Implements MSA and MSA1-9 (same as z15).
+     * Implements MSA and MSA1-9 (same as z15, no need to repeat).
      */
-    static const struct OPENSSL_s390xcap_st z16 = z15;
 
     char *tok_begin, *tok_end, *buff, tok[S390X_STFLE_MAX][LEN + 1];
     int rc, off, i, n;
@@ -730,7 +731,7 @@ static int parse_env(struct OPENSSL_s390xcap_st *cap)
         else if TOK_CPU(z13)
         else if TOK_CPU(z14)
         else if TOK_CPU(z15)
-        else if TOK_CPU(z16)
+        else if TOK_CPU_ALIAS(z16, z15)
 
         /* whitespace(ignored) or invalid tokens */
         else {