]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Fix compilation warning
authorCarmine Scarpitta <cscarpit@cisco.com>
Sun, 18 Aug 2024 11:02:06 +0000 (13:02 +0200)
committerCarmine Scarpitta <cscarpit@cisco.com>
Sun, 18 Aug 2024 11:03:04 +0000 (13:03 +0200)
Make sure the variable `srv6` is not NULL before dereferencing it.

Fixes the following compilation warnings:

```
error 15-Aug-2024 14:20:01 zebra/zebra_srv6_vty.c:974:8: warning: Access to field 'locators' results in a dereference of a null pointer (loaded from variable 'srv6') [core.NullDereference]
error 15-Aug-2024 14:20:01                 for (ALL_LIST_ELEMENTS_RO(srv6->locators, node, locator)) {
error 15-Aug-2024 14:20:01                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error 15-Aug-2024 14:20:01 ./lib/linklist.h:345:11: note: expanded from macro 'ALL_LIST_ELEMENTS_RO'
error 15-Aug-2024 14:20:01         (node) = listhead(list), ((data) = NULL);                              \
error 15-Aug-2024 14:20:01                  ^~~~~~~~~~~~~~
error 15-Aug-2024 14:20:01 ./lib/linklist.h:63:22: note: expanded from macro 'listhead'
error 15-Aug-2024 14:20:01 #define listhead(X) ((X) ? ((X)->head) : NULL)
error 15-Aug-2024 14:20:01                      ^
```

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

index c664a9c69f1ef758256223666427ef7dadd81f40..5a80524149027b6ac91f0fa51672780a09a98c06 100644 (file)
@@ -969,7 +969,7 @@ static int zebra_sr_config(struct vty *vty)
                                &srv6->encap_src_addr);
                }
        }
-       if (zebra_srv6_is_enable()) {
+       if (srv6 && zebra_srv6_is_enable()) {
                vty_out(vty, "  locators\n");
                for (ALL_LIST_ELEMENTS_RO(srv6->locators, node, locator)) {
                        inet_ntop(AF_INET6, &locator->prefix.prefix,