misc: pass NULL instead of 0 for pointer in variadic functions 88/36588/2
authorAndreas Schultz <[email protected]>
Fri, 15 May 2020 09:50:07 +0000 (11:50 +0200)
committerIvan Shvedunov <[email protected]>
Tue, 5 Jul 2022 23:32:18 +0000 (03:32 +0400)
0 is not NULL (at least not in all cases), passing 0 into a variadic
function in a place where the consumer reads it as pointer might
leave parts of the pointer uninitilized and hence filled with random
data.

It seems that this used to work with gcc, but clang seems to treat the
0 in those places as a 32bit integer.

Type: fix

Signed-off-by: Ivan Shvedunov <[email protected]>
Signed-off-by: Andreas Schultz <[email protected]>
Change-Id: I37d975eef5a1ad98fbfb65ebe47d73458aafea00

src/plugins/mactime/mactime_top.c
src/vlib/log.c
src/vlib/unix/cli.c
src/vlib/unix/main.c
src/vnet/session/application.c

index abcb530..d7223f4 100644 (file)
@@ -441,7 +441,7 @@ print_device_table (mt_main_t * mm)
 {
   mactime_device_t *dev;
 
-  fformat (stdout, "%U", format_device, 0 /* header */ , 0 /* verbose */ );
+  fformat (stdout, "%U", format_device, NULL /* header */, 0 /* verbose */);
   /* *INDENT-OFF* */
   pool_foreach (dev, mm->devices)
    {
index a7791e4..d084511 100644 (file)
@@ -413,10 +413,9 @@ show_log (vlib_main_t * vm,
   while (count--)
     {
       e = vec_elt_at_index (lm->entries, i);
-      vlib_cli_output (vm, "%U %-10U %-14U %v",
-                      format_time_float, 0, e->timestamp + time_offset,
-                      format_vlib_log_level, e->level,
-                      format_vlib_log_class, e->class, e->string);
+      vlib_cli_output (vm, "%U %-10U %-14U %v", format_time_float, NULL,
+                      e->timestamp + time_offset, format_vlib_log_level,
+                      e->level, format_vlib_log_class, e->class, e->string);
       i = (i + 1) % lm->size;
     }
 
index cb8aa9f..a647dd7 100644 (file)
@@ -2576,9 +2576,8 @@ more:
     {
       static u8 *lv;
       vec_reset_length (lv);
-      lv = format (lv, "%U[%d]: %v",
-                  format_timeval, 0 /* current bat-time */ ,
-                  0 /* current bat-format */ ,
+      lv = format (lv, "%U[%d]: %v", format_timeval,
+                  NULL /* current bat-format */, 0 /* current bat-time */,
                   cli_file_index, cf->current_command);
       if ((vec_len (cf->current_command) > 0) &&
          (cf->current_command[vec_len (cf->current_command) - 1] != '\n'))
index fd8a7e8..6b1a32c 100644 (file)
@@ -327,17 +327,16 @@ startup_config_process (vlib_main_t * vm,
        {
          u8 *lv = 0;
          lv = format (lv, "%U: ***** Startup Config *****\n%v",
-                      format_timeval, 0 /* current bat-time */ ,
-                      0 /* current bat-format */ ,
-                      buf);
+                      format_timeval, NULL /* current bat-format */,
+                      0 /* current bat-time */, buf);
          {
            int rv __attribute__ ((unused)) =
              write (um->log_fd, lv, vec_len (lv));
          }
          vec_reset_length (lv);
-         lv = format (lv, "%U: ***** End Startup Config *****\n",
-                      format_timeval, 0 /* current bat-time */ ,
-                      0 /* current bat-format */ );
+         lv =
+           format (lv, "%U: ***** End Startup Config *****\n", format_timeval,
+                   NULL /* current bat-format */, 0 /* current bat-time */);
          {
            int rv __attribute__ ((unused)) =
              write (um->log_fd, lv, vec_len (lv));
@@ -477,9 +476,8 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
            {
              u8 *lv = 0;
              lv = format (0, "%U: ***** Start: PID %d *****\n",
-                          format_timeval, 0 /* current bat-time */ ,
-                          0 /* current bat-format */ ,
-                          getpid ());
+                          format_timeval, NULL /* current bat-format */,
+                          0 /* current bat-time */, getpid ());
              {
                int rv __attribute__ ((unused)) =
                  write (um->log_fd, lv, vec_len (lv));
index 7f88c7a..67dc7d6 100644 (file)
@@ -1681,7 +1681,7 @@ application_format_listeners (application_t * app, int verbose)
 
   if (!app)
     {
-      vlib_cli_output (vm, "%U", format_app_worker_listener, 0 /* header */ ,
+      vlib_cli_output (vm, "%U", format_app_worker_listener, NULL /* header */,
                       0, 0, verbose);
       return;
     }