nat: fix coverity errors 34/31134/4
authorOle Troan <ot@cisco.com>
Sat, 6 Feb 2021 12:02:41 +0000 (13:02 +0100)
committerNeale Ranns <neale@graphiant.com>
Tue, 9 Feb 2021 09:56:56 +0000 (09:56 +0000)
Including a general missing free in fromjson autogenerated code.

Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: I9ab2b0193135e2fb3d62d51b3c114df56969e341
Signed-off-by: Ole Troan <ot@cisco.com>
src/plugins/nat/pnat/pnat.h
src/plugins/nat/pnat/pnat_cli.c
src/plugins/nat/test/test_pnat.py
src/tools/vppapigen/vppapigen_c.py

index c5869ce..af64fce 100644 (file)
@@ -109,12 +109,11 @@ static inline void
 pnat_calc_key(u32 sw_if_index, pnat_attachment_point_t attachment,
               ip4_address_t src, ip4_address_t dst, u8 protocol, u16 sport,
               u16 dport, pnat_mask_fast_t mask, clib_bihash_kv_16_8_t *kv) {
-    kv->key[0] = kv->key[1] = 0;
     kv->key[0] = (u64)src.as_u32 << 32 | dst.as_u32;
     kv->key[0] &= mask.as_u64[0];
-    kv->key[1] |=
+    kv->key[1] =
         (u64)protocol << 56 | (u64)sw_if_index << 36 | (u64)attachment << 32;
-    kv->key[1] |= sport << 16 | dport;
+    kv->key[1] |= (u32)sport << 16 | dport;
     kv->key[1] &= mask.as_u64[1];
 }
 
index 2d38901..84dfd8d 100644 (file)
@@ -97,12 +97,12 @@ uword unformat_pnat_5tuple(unformat_input_t *input, va_list *args) {
         else if (unformat(input, "dst %U", unformat_ip4_address, &t->dst))
             t->mask |= PNAT_DA;
         else if (unformat(input, "sport %d", &sport)) {
-            if (sport < 0 || sport > 65535)
+            if (sport == 0 || sport > 65535)
                 return 0;
             t->mask |= PNAT_SPORT;
             t->sport = sport;
         } else if (unformat(input, "dport %d", &dport)) {
-            if (dport < 0 || dport > 65535)
+            if (dport == 0 || dport > 65535)
                 return 0;
             t->mask |= PNAT_DPORT;
             t->dport = dport;
index 5e52fa9..d5b6005 100644 (file)
@@ -93,10 +93,10 @@ class TestPNAT(VppTestCase):
                 'rewrite': {'mask': 0xa, 'dst': self.pg1.remote_ip4,
                             'dport': 5555},
                 'send': (IP(src=self.pg0.remote_ip4, dst='10.10.10.10') /
-                         UDP(dport=6871)),
+                         UDP(sport=65530, dport=6871)),
                 'reply': (IP(src=self.pg0.remote_ip4,
                              dst=self.pg1.remote_ip4) /
-                          UDP(dport=5555))
+                          UDP(sport=65530, dport=5555))
             },
             {
                 'input': PNAT_IP4_INPUT,
index 0798e9a..1886c98 100644 (file)
@@ -367,7 +367,7 @@ class FromJSON():
             write('    {msgvar} = {t}_fromjson({msgvar}, '
                   '{msgsize}, item, &a->{n});\n'
                   .format(t=t, n=o.fieldname, msgvar=msgvar, msgsize=msgsize))
-            write('    if (!{msgvar}) return 0;\n'.format(msgvar=msgvar))
+            write('    if (!{msgvar}) {{ free(a); return 0;}} \n'.format(msgvar=msgvar))
 
         write('    // end field {}\n'.format(o.fieldname))