diff mbox series

[ovs-dev,3/4] ovn-nbctl: Avoid uninitialized value for mirror index.

Message ID 20240626133007.694177-4-amusil@redhat.com
State Accepted
Headers show
Series Fix issues reported by coverity | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_ovn-kubernetes success github build: passed

Commit Message

Ales Musil June 26, 2024, 1:30 p.m. UTC
The local mirror doesn't have an index, avoid storing
uninitialized value in that case. Also prevent from index
printing for local mirrors.

Signed-off-by: Ales Musil <amusil@redhat.com>
---
 tests/ovn-nbctl.at    | 9 +++++++++
 utilities/ovn-nbctl.c | 8 +++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at
index 19c83a4a5..31de30921 100644
--- a/tests/ovn-nbctl.at
+++ b/tests/ovn-nbctl.at
@@ -452,6 +452,7 @@  OVN_NBCTL_TEST([ovn_nbctl_mirrors], [mirrors], [
 check ovn-nbctl mirror-add mirror1 gre 0 from-lport 10.10.10.1
 check ovn-nbctl mirror-add mirror2 erspan 1 to-lport 10.10.10.2
 check ovn-nbctl mirror-add mirror3 gre 2 to-lport 10.10.10.3
+check ovn-nbctl mirror-add mirror-local local both 10.10.10.3
 check ovn-nbctl ls-add sw0
 check ovn-nbctl lsp-add sw0 sw0-port1
 check ovn-nbctl lsp-add sw0 sw0-port2
@@ -480,6 +481,11 @@  check_column "$mirror3uuid" nb:Logical_Switch_Port mirror_rules name=sw0-port3
 
 dnl Verify if multiple ports are attached to the same mirror properly
 AT_CHECK([ovn-nbctl mirror-list], [0], [dnl
+mirror-local:
+  Type     :  local
+  Sink     :  10.10.10.3
+  Filter   :  both
+
 mirror1:
   Type     :  gre
   Sink     :  10.10.10.1
@@ -500,6 +506,9 @@  mirror3:
 
 ])
 
+dnl Remove the local mirror
+check ovn-nbctl mirror-del mirror-local
+
 dnl Detach one source port from mirror
 check ovn-nbctl lsp-detach-mirror sw0-port3 mirror3
 
diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
index 32ca4f750..c37cc010c 100644
--- a/utilities/ovn-nbctl.c
+++ b/utilities/ovn-nbctl.c
@@ -7691,7 +7691,7 @@  nbctl_mirror_add(struct ctl_context *ctx)
     const char *sink = NULL;
     const char *type = NULL;
     const char *name = NULL;
-    int64_t index;
+    int64_t index = -1;
     char *error = NULL;
     const struct nbrec_mirror *mirror_check = NULL;
     int pos = 1;
@@ -7824,8 +7824,10 @@  nbctl_mirror_list(struct ctl_context *ctx)
         ds_put_format(&ctx->output, "  Type     :  %s\n", mirror->type);
         ds_put_format(&ctx->output, "  Sink     :  %s\n", mirror->sink);
         ds_put_format(&ctx->output, "  Filter   :  %s\n", mirror->filter);
-        ds_put_format(&ctx->output, "  Index/Key:  %ld\n",
-                      (long int) mirror->index);
+        if (strcmp(mirror->type, "local")) {
+            ds_put_format(&ctx->output, "  Index/Key:  %"PRId64"\n",
+                          mirror->index);
+        }
         ds_put_cstr(&ctx->output, "\n");
     }