vppinfra: fix format_c_identifier vector overflow 43/27943/2
authorBenoît Ganne <bganne@cisco.com>
Thu, 16 Jul 2020 10:03:35 +0000 (12:03 +0200)
committerDamjan Marion <dmarion@me.com>
Thu, 16 Jul 2020 21:41:12 +0000 (21:41 +0000)
In case of vector, we must check length before trying to access element.
Also fix wrong DPDK plugin workaround.

Type: fix

Change-Id: I2ecef1c88ebef2362f48cab0d462699aa43cd4b9
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/plugins/dpdk/device/format.c
src/vppinfra/std-formats.c

index dad1505..19476cb 100644 (file)
@@ -710,12 +710,10 @@ format_dpdk_device (u8 * s, va_list * args)
           xstat = vec_elt_at_index(xd->xstats, i);
           if (verbose == 2 || (verbose && xstat->value))
             {
-              /* format_c_identifier doesn't like c strings inside vector */
-              u8 * name = format(0,"%s", xstat_names[i].name);
               xs = format(xs, "\n%U%-38U%16Lu",
                           format_white_space, indent + 4,
-                          format_c_identifier, name, xstat->value);
-              vec_free(name);
+                          format_c_identifier, xstat_names[i].name,
+                          xstat->value);
             }
         }
       /* *INDENT-ON* */
index b771b94..62d309e 100644 (file)
@@ -281,7 +281,7 @@ format_c_identifier (u8 * s, va_list * va)
     l = vec_len (id);
 
   if (id)
-    for (i = 0; id[i] != 0 && i < l; i++)
+    for (i = 0; i < l && id[i] != 0; i++)
       {
        u8 c = id[i];