app/pdump: fix string overflow
authorReshma Pattan <reshma.pattan@intel.com>
Fri, 24 Jun 2016 16:36:22 +0000 (17:36 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Mon, 27 Jun 2016 14:50:20 +0000 (16:50 +0200)
replaced strncpy with snprintf for safely
copying the strings.

Coverity issue: 127351

Fixes: caa7028276b8 ("app/pdump: add tool for packet capturing")

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
Acked-by: John McNamara <john.mcnamara@intel.com>
app/pdump/main.c

index f8923b9..fe4d38a 100644 (file)
@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)
        struct pdump_tuples *pt = extra_args;
 
        if (!strcmp(key, PDUMP_RX_DEV_ARG)) {
-               strncpy(pt->rx_dev, value, strlen(value));
+               snprintf(pt->rx_dev, sizeof(pt->rx_dev), "%s", value);
                /* identify the tx stream type for pcap vdev */
                if (if_nametoindex(pt->rx_dev))
                        pt->rx_vdev_stream_type = IFACE;
        } else if (!strcmp(key, PDUMP_TX_DEV_ARG)) {
-               strncpy(pt->tx_dev, value, strlen(value));
+               snprintf(pt->tx_dev, sizeof(pt->tx_dev), "%s", value);
                /* identify the tx stream type for pcap vdev */
                if (if_nametoindex(pt->tx_dev))
                        pt->tx_vdev_stream_type = IFACE;