vlib: fix dangling reference in node_by_name hash 88/32688/2
authorDave Barach <dave@barachs.net>
Fri, 11 Jun 2021 16:57:23 +0000 (12:57 -0400)
committerFlorin Coras <florin.coras@gmail.com>
Sun, 13 Jun 2021 17:42:07 +0000 (17:42 +0000)
When recycling a debug CLI process node, unix_cli_file_add() needs to
delete and recreate the related node_by_name hash table entry.

Type: fix

Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I635da4918509d5b22eae37627c2d9b3608380ca6

src/vlib/unix/cli.c

index 6c98867..44ec11f 100644 (file)
@@ -2863,6 +2863,7 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd)
 {
   unix_main_t *um = &unix_main;
   clib_file_main_t *fm = &file_main;
+  vlib_node_main_t *nm = &vlib_get_main ()->node_main;
   unix_cli_file_t *cf;
   clib_file_t template = { 0 };
   vlib_main_t *vm = um->vlib_main;
@@ -2896,10 +2897,12 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd)
          old_name = n->name;
          n->name = (u8 *) name;
        }
+      ASSERT (old_name);
+      hash_unset (nm->node_by_name, old_name);
+      hash_set (nm->node_by_name, name, n->index);
       vec_free (old_name);
 
       vlib_node_set_state (vm, n->index, VLIB_NODE_STATE_POLLING);
-
       _vec_len (cm->unused_cli_process_node_indices) = l - 1;
     }
   else