Skip to contentSkip to conversation

Avoid warning about missing braces when initialising key struct

PATCH In review Arne Schwabe 3 participants 5 messages Mar 7, 2023 – Mar 8, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid warning about missing braces when initialising key struct

This avoids the warning from gcc about initialising the key2 struct

Change-Id Ia73d24923b1efd99263f33ce13d90e04b59bd980
---
 src/openvpn/tls_crypt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpn/tls_crypt.c +2 -1
index 81098355e..e84d979e9 100644
@@ -348,7 +348,8 @@ tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *original_key,
         msg(M_FATAL, "ERROR: invalid tls-crypt-v2 client key format");
     }
 
-    struct key2 key2 = { .n = 2, .keys = { 0 } };
+    struct key2 key2 = { .n = 2, .keys = {{{ 0 }}} };
+
     if (!buf_read(&client_key, &key2.keys, sizeof(key2.keys)))
     {
         msg(M_FATAL, "ERROR: not enough data in tls-crypt-v2 client key");
Signature · 1 line
2.37.1 (Apple Git-137.1)
#1 lore raw

Hi,

Quoted 13 lines · Arne Schwabe

This avoids the warning from gcc about initialising the key2 struct

Change-Id Ia73d24923b1efd99263f33ce13d90e04b59bd980
---
  src/openvpn/tls_crypt.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpn/tls_crypt.c +0 -0
index 81098355e..e84d979e9 100644

src/openvpn/tls_crypt.c tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *original_key, · line 351

Quoted 5 lines
src/openvpn/tls_crypt.c +1 -1
@@ -348,7 +348,8 @@ tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *original_key,
          msg(M_FATAL, "ERROR: invalid tls-crypt-v2 client key format");
      }
 
-    struct key2 key2 = { .n = 2, .keys = { 0 } };
+    struct key2 key2 = { .n = 2, .keys = {{{ 0 }}} };

why not just struct key2 key2 = { .n = 2 } ?

Cheers,

Quoted 4 lines
src/openvpn/tls_crypt.c +1 -0
+
      if (!buf_read(&client_key, &key2.keys, sizeof(key2.keys)))
      {
          msg(M_FATAL, "ERROR: not enough data in tls-crypt-v2 client key");
Signature · 1 line
Antonio Quartulli
#2 lore raw

Am 08.03.23 um 11:03 schrieb Antonio Quartulli:

Quoted 11 lines

Hi,

Quoted 8 lines · Arne Schwabe

This avoids the warning from gcc about initialising the key2 struct

Change-Id Ia73d24923b1efd99263f33ce13d90e04b59bd980

---
  src/openvpn/tls_crypt.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 12 lines

src/openvpn/tls_crypt.c tls_crypt_v2_init_client_key(struct key_ctx_bi · line 351

Quoted 10 lines
src/openvpn/tls_crypt.c +1 -1
index 81098355e..e84d979e9 100644
@@ -348,7 +348,8 @@ tls_crypt_v2_init_client_key(struct key_ctx_bi 
 *key, struct key2 *original_key,
           msg(M_FATAL, "ERROR: invalid tls-crypt-v2 client key format");
       }
-    struct key2 key2 = { .n = 2, .keys = { 0 } };
+    struct key2 key2 = { .n = 2, .keys = {{{ 0 }}} };

why not just struct key2 key2 = { .n = 2 } ?

That will initialise the whole struct to 2 including the key material, which I would like to avoid.

Arne

#3 lore raw

PATCH v2 1/1 Avoid warning about missing braces when initialising key struct

---

As concluded on IRC, this version does what we want it to do. We also quickly tested with some sample program to make sure we weren't making this up.

 src/openvpn/tls_crypt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/tls_crypt.c +1 -1
index 81098355..3b68d186 100644
@@ -348,7 +348,7 @@ tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *original_key,
         msg(M_FATAL, "ERROR: invalid tls-crypt-v2 client key format");
     }
 
-    struct key2 key2 = { .n = 2, .keys = { 0 } };
+    struct key2 key2 = { .n = 2 };
     if (!buf_read(&client_key, &key2.keys, sizeof(key2.keys)))
     {
         msg(M_FATAL, "ERROR: not enough data in tls-crypt-v2 client key");
Signature · 1 line
2.39.2
Acked-by on v2 1/1
#4 lore raw

Confirmed that it pacifies github, and tests still pass.

Your patch has been applied to the master and release/2.6 branch.

commit 5a14a5ea572ec88e2a9e7bfdad9d5fe31025c021 (master) commit 26417824ff81ba1dd18b03a40822da533018a892 (release/2.6)

Author: Antonio Quartulli
Date:   Wed Mar 8 14:37:43 2023 +0100
     Avoid warning about missing braces when initialising key struct

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering