diff mbox series

[ovs-dev,v2] conntrack: Do not use {0} to initialize unions.

Message ID 20240508162932.1410307-1-xsimonar@redhat.com
State Accepted
Commit 4989dc7e0e95df42d448c30b505a89a416b44e89
Delegated to: Ilya Maximets
Headers show
Series [ovs-dev,v2] conntrack: Do not use {0} to initialize unions. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Xavier Simonart May 8, 2024, 4:29 p.m. UTC
In the following case:
    union ct_addr {
        unsigned int ipv4;
        struct in6_addr ipv6;
    };
    union ct_addr zero_ip = {0};

The ipv6 field might not be properly initialized.
For instance, clang 18.1.1 does not initialize the ipv6 field.

Reported-at: https://issues.redhat.com/browse/FDP-608
Signed-off-by: Xavier Simonart <xsimonar@redhat.com>
---
v2: updated based on nit from Paolo.
---
 lib/conntrack.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Paolo Valerio May 9, 2024, 11:37 a.m. UTC | #1
Xavier Simonart <xsimonar@redhat.com> writes:

> In the following case:
>     union ct_addr {
>         unsigned int ipv4;
>         struct in6_addr ipv6;
>     };
>     union ct_addr zero_ip = {0};
>
> The ipv6 field might not be properly initialized.
> For instance, clang 18.1.1 does not initialize the ipv6 field.
>
> Reported-at: https://issues.redhat.com/browse/FDP-608
> Signed-off-by: Xavier Simonart <xsimonar@redhat.com>
> ---
> v2: updated based on nit from Paolo.
> ---

Thanks Xavier.

Acked-by: Paolo Valerio <pvalerio@redhat.com>
Ilya Maximets May 14, 2024, 7:43 a.m. UTC | #2
On 5/9/24 13:37, Paolo Valerio wrote:
> Xavier Simonart <xsimonar@redhat.com> writes:
> 
>> In the following case:
>>     union ct_addr {
>>         unsigned int ipv4;
>>         struct in6_addr ipv6;
>>     };
>>     union ct_addr zero_ip = {0};
>>
>> The ipv6 field might not be properly initialized.
>> For instance, clang 18.1.1 does not initialize the ipv6 field.
>>
>> Reported-at: https://issues.redhat.com/browse/FDP-608
>> Signed-off-by: Xavier Simonart <xsimonar@redhat.com>
>> ---
>> v2: updated based on nit from Paolo.
>> ---
> 
> Thanks Xavier.
> 
> Acked-by: Paolo Valerio <pvalerio@redhat.com>

Thanks, Xavier and Paolo!

Applied and backported down to 2.17.

Bets regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/lib/conntrack.c b/lib/conntrack.c
index 16e1c8bb5..655b87ba9 100644
--- a/lib/conntrack.c
+++ b/lib/conntrack.c
@@ -2302,7 +2302,8 @@  find_addr(const struct conn_key *key, union ct_addr *min,
           uint32_t hash, bool ipv4,
           const struct nat_action_info_t *nat_info)
 {
-    const union ct_addr zero_ip = {0};
+    union ct_addr zero_ip;
+    memset(&zero_ip, 0, sizeof zero_ip);
 
     /* All-zero case. */
     if (!memcmp(min, &zero_ip, sizeof *min)) {
@@ -2394,14 +2395,18 @@  nat_get_unique_tuple(struct conntrack *ct, struct conn *conn,
 {
     struct conn_key *fwd_key = &conn->key_node[CT_DIR_FWD].key;
     struct conn_key *rev_key = &conn->key_node[CT_DIR_REV].key;
-    union ct_addr min_addr = {0}, max_addr = {0}, addr = {0};
     bool pat_proto = fwd_key->nw_proto == IPPROTO_TCP ||
                      fwd_key->nw_proto == IPPROTO_UDP ||
                      fwd_key->nw_proto == IPPROTO_SCTP;
     uint16_t min_dport, max_dport, curr_dport;
     uint16_t min_sport, max_sport, curr_sport;
+    union ct_addr min_addr, max_addr, addr;
     uint32_t hash, port_off, basis;
 
+    memset(&min_addr, 0, sizeof min_addr);
+    memset(&max_addr, 0, sizeof max_addr);
+    memset(&addr, 0, sizeof addr);
+
     basis = (nat_info->nat_flags & NAT_PERSISTENT) ? 0 : ct->hash_basis;
     hash = nat_range_hash(fwd_key, basis, nat_info);