policer: fix coverity warning/NULL dereference 55/34255/2
authorKlement Sekera <ksekera@cisco.com>
Wed, 27 Oct 2021 08:56:38 +0000 (10:56 +0200)
committerDamjan Marion <dmarion@me.com>
Fri, 29 Oct 2021 16:20:52 +0000 (16:20 +0000)
Add a NULL check in case of hash lookup failure to make coverity happy.

Type: fix
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Change-Id: I3cfa5960458d3618f1277ba442b4ca5ca15064ea

src/vnet/policer/policer.c

index 516a029..9eb5641 100644 (file)
@@ -737,8 +737,16 @@ show_policer_command_fn (vlib_main_t * vm,
        templ = pool_elt_at_index (pm->policer_templates, pool_index);
        vlib_cli_output (vm, "Name \"%s\" %U ", name, format_policer_config,
                         config);
-       vlib_cli_output (vm, "Template %U", format_policer_instance, templ,
-                        pi[0]);
+       if (pi)
+         {
+           vlib_cli_output (vm, "Template %U", format_policer_instance, templ,
+                            pi[0]);
+         }
+       else
+         {
+           vlib_cli_output (
+             vm, "Cannot print template - policer index hash lookup failed");
+         }
        vlib_cli_output (vm, "-----------");
       }
   }));