event/opdl: replace sprintf with snprintf
authorPallantla Poornima <pallantlax.poornima@intel.com>
Mon, 4 Feb 2019 07:18:02 +0000 (07:18 +0000)
committerJerin Jacob <jerinj@marvell.com>
Fri, 15 Mar 2019 05:46:50 +0000 (06:46 +0100)
sprintf function is not secure as it doesn't check the length of string.
More secure function snprintf is used.

Fixes: 3c7f3dcfb0 ("event/opdl: add PMD main body and helper function")
Cc: stable@dpdk.org
Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
drivers/event/opdl/opdl_evdev.c
drivers/event/opdl/opdl_evdev_xstats.c

index a4f0bc8..d2d2be4 100644 (file)
@@ -422,16 +422,17 @@ opdl_dump(struct rte_eventdev *dev, FILE *f)
                        else
                                p_type = "????";
 
-                       sprintf(queue_id, "%02u", port->external_qid);
+                       snprintf(queue_id, sizeof(queue_id), "%02u",
+                                       port->external_qid);
                        if (port->p_type == OPDL_REGULAR_PORT ||
                                        port->p_type == OPDL_ASYNC_PORT)
-                               sprintf(total_cyc,
+                               snprintf(total_cyc, sizeof(total_cyc),
                                        " %'16"PRIu64"",
                                        (cpg != 0 ?
                                         port->port_stat[total_cycles] / cpg
                                         : 0));
                        else
-                               sprintf(total_cyc,
+                               snprintf(total_cyc, sizeof(total_cyc),
                                        "             ----");
                        fprintf(f,
                                "%4s %10u %8u %9s %'16"PRIu64" %'16"PRIu64" %s "
index 0e6c6bd..27b3d88 100644 (file)
@@ -32,10 +32,9 @@ opdl_xstats_init(struct rte_eventdev *dev)
                        uint32_t index = (i * max_num_port_xstat) + j;
 
                        /* Name */
-                       sprintf(device->port_xstat[index].stat.name,
-                              "port_%02u_%s",
-                              i,
-                              port_xstat_str[j]);
+                       snprintf(device->port_xstat[index].stat.name,
+                               sizeof(device->port_xstat[index].stat.name),
+                               "port_%02u_%s", i, port_xstat_str[j]);
 
                        /* ID */
                        device->port_xstat[index].id = index;