]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Fix wrong variable used in `for` loop
authorCarmine Scarpitta <cscarpit@cisco.com>
Fri, 21 Jun 2024 15:41:34 +0000 (17:41 +0200)
committerCarmine Scarpitta <cscarpit@cisco.com>
Mon, 24 Jun 2024 08:44:14 +0000 (10:44 +0200)
The `for` loop starting at line 1848 searches the `func_allocated` array
for a pointer that points to a specific `sid_wide_func` element.

The loop should iterate over all the elements of the `func_allocated`
array and dereference each element to see if it is the one we are
looking for.

Currently, the loop is using the wrong variable to iterate over the
array.

Let's fix this issue by using the correct variable in the loop.

Fixes CID 1594014
Fixes CID 1594016

** CID 1594014:  Null pointer dereferences  (FORWARD_NULL)
/zebra/zebra_srv6.c: 1860 in release_srv6_sid_func_explicit()

________________________________________________________________________________________________________
*** CID 1594014:  Null pointer dereferences  (FORWARD_NULL)
/zebra/zebra_srv6.c: 1860 in release_srv6_sid_func_explicit()
1854
1855      /* Lookup SID function in the functions allocated list of EWLIB range */
1856      for (ALL_LIST_ELEMENTS_RO(block->u.usid
1857        .wide_lib[sid_func]
1858        .func_allocated,
1859        node, sid_func_ptr))
     CID 1594014:  Null pointer dereferences  (FORWARD_NULL)
     Dereferencing null pointer "sid_wide_func_ptr".
1860      if (*sid_wide_func_ptr == sid_wide_func)
1861      break;
1862
1863      /* Ensure that the SID function is allocated */
1864      if (!sid_wide_func_ptr) {
1865      zlog_warn("%s: failed to release wide SID function %u, function is not allocated",

** CID 1594016:  Possible Control flow issues  (DEADCODE)
/zebra/zebra_srv6.c: 1871 in release_srv6_sid_func_explicit()

________________________________________________________________________________________________________
*** CID 1594016:  Possible Control flow issues  (DEADCODE)
/zebra/zebra_srv6.c: 1871 in release_srv6_sid_func_explicit()
1865      zlog_warn("%s: failed to release wide SID function %u, function is not allocated",
1866        __func__, sid_wide_func);
1867      return -1;
1868      }
1869
1870      /* Release the SID function from the EWLIB range */
     CID 1594016:  Possible Control flow issues  (DEADCODE)
     Execution cannot reach this statement: "listnode_delete(block->u.us...".
1871      listnode_delete(block->u.usid.wide_lib[sid_func]
1872      .func_allocated,
1873      sid_wide_func_ptr);
1874      zebra_srv6_sid_func_free(sid_wide_func_ptr);
1875      } else {
1876      zlog_warn("%s: function %u is outside ELIB [%u/%u] and EWLIB alloc ranges [%u/%u]",

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
zebra/zebra_srv6.c

index 2c1f86a3fc3ccb7e6752c7a96d4601a9864f8db2..be335a5dedf278783400ff92ad667c19a8121d22 100644 (file)
@@ -1843,7 +1843,7 @@ static bool release_srv6_sid_func_explicit(struct zebra_srv6_sid_block *block,
                                for (ALL_LIST_ELEMENTS_RO(block->u.usid
                                                                  .wide_lib[sid_func]
                                                                  .func_allocated,
-                                                         node, sid_func_ptr))
+                                                         node, sid_wide_func_ptr))
                                        if (*sid_wide_func_ptr == sid_wide_func)
                                                break;