misc: address sanitizer: fix instrumentation
[vpp.git] / src / vlibmemory / vlib_api_cli.c
index 0d5ce96..db48711 100755 (executable)
@@ -101,7 +101,7 @@ vl_api_client_command (vlib_main_t * vm,
   vl_api_registration_t **regpp, *regp;
   svm_queue_t *q;
   char *health;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   u32 *confused_indices = 0;
 
   if (!pool_elts (am->vl_clients))
@@ -161,7 +161,7 @@ static clib_error_t *
 vl_api_status_command (vlib_main_t * vm,
                       unformat_input_t * input, vlib_cli_command_t * cli_cmd)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
 
   /* check if rx_trace and tx_trace are not null pointers */
   if (am->rx_trace == 0)
@@ -228,7 +228,7 @@ vl_api_message_table_command (vlib_main_t * vm,
                              unformat_input_t * input,
                              vlib_cli_command_t * cli_cmd)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   int i;
   int verbose = 0;
 
@@ -304,7 +304,7 @@ vl_api_show_plugin_command (vlib_main_t * vm,
                            unformat_input_t * input,
                            vlib_cli_command_t * cli_cmd)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   vl_api_msg_range_t *rp = 0;
   int i;
 
@@ -402,7 +402,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
   struct stat statb;
   size_t file_size;
   u8 *msg;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   u8 *tmpbuf = 0;
   u32 nitems, nitems_msgtbl;
   void **saved_print_handlers = 0;
@@ -442,6 +442,8 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
     }
   close (fd);
 
+  CLIB_MEM_UNPOISON (hp, file_size);
+
   nitems = ntohl (hp->nitems);
 
   if (last_index == (u32) ~ 0)
@@ -454,6 +456,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
       vlib_cli_output (vm, "Range (%d, %d) outside file range (0, %d)\n",
                       first_index, last_index, nitems - 1);
       munmap (hp, file_size);
+      CLIB_MEM_POISON (hp, file_size);
       return;
     }
   if (hp->wrapped)
@@ -465,6 +468,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
       saved_print_handlers = (void **) vec_dup (am->msg_print_handlers);
       vl_msg_api_custom_dump_configure (am);
     }
+
   msg = (u8 *) (hp + 1);
 
   u16 *msgid_vec = 0;
@@ -503,6 +507,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
        {
          vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
          munmap (hp, file_size);
+         CLIB_MEM_POISON (hp, file_size);
          return;
        }
       msg += size;
@@ -534,6 +539,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
        {
          vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
          munmap (hp, file_size);
+         CLIB_MEM_POISON (hp, file_size);
          vec_free (tmpbuf);
          am->replay_in_progress = 0;
          return;
@@ -548,7 +554,8 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
        * Endian swap if needed. All msg data is supposed to be in
        * network byte order.
        */
-      if ((which == DUMP && clib_arch_is_little_endian))
+      if (((which == DUMP || which == CUSTOM_DUMP)
+          && clib_arch_is_little_endian))
        {
          void (*endian_fp) (void *);
          if (msg_id >= vec_len (am->msg_endian_handlers)
@@ -556,6 +563,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
            {
              vlib_cli_output (vm, "Ugh: msg id %d no endian swap\n", msg_id);
              munmap (hp, file_size);
+             CLIB_MEM_POISON (hp, file_size);
              vec_free (tmpbuf);
              am->replay_in_progress = 0;
              return;
@@ -658,6 +666,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
     }
 
   munmap (hp, file_size);
+  CLIB_MEM_POISON (hp, file_size);
   vec_free (tmpbuf);
   am->replay_in_progress = 0;
 }
@@ -667,7 +676,7 @@ api_trace_command_fn (vlib_main_t * vm,
                      unformat_input_t * input, vlib_cli_command_t * cmd)
 {
   u32 nitems = 256 << 10;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   vl_api_trace_which_t which = VL_API_TRACE_RX;
   u8 *filename = 0;
   u8 *chroot_filename = 0;
@@ -803,7 +812,7 @@ vl_api_trace_command (vlib_main_t * vm,
 {
   u32 nitems = 1024;
   vl_api_trace_which_t which = VL_API_TRACE_RX;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
@@ -880,7 +889,7 @@ api_trace_config_fn (vlib_main_t * vm, unformat_input_t * input)
 {
   u32 nitems = 256 << 10;
   vl_api_trace_which_t which = VL_API_TRACE_RX;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
@@ -913,7 +922,7 @@ VLIB_CONFIG_FUNCTION (api_trace_config_fn, "api-trace");
 static clib_error_t *
 api_queue_config_fn (vlib_main_t * vm, unformat_input_t * input)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   u32 nitems;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
@@ -1003,7 +1012,7 @@ dump_api_table_file_command_fn (vlib_main_t * vm,
                                vlib_cli_command_t * cmd)
 {
   u8 *filename = 0;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
   serialize_main_t _sm, *sm = &_sm;
   clib_error_t *error;
   u32 nmsgs;