examples/ip_pipeline: replace strncpy with strlcpy
authorJasvinder Singh <jasvinder.singh@intel.com>
Tue, 17 Apr 2018 13:17:19 +0000 (14:17 +0100)
committerCristian Dumitrescu <cristian.dumitrescu@intel.com>
Tue, 8 May 2018 11:35:10 +0000 (13:35 +0200)
The destination string may not have a null termination if
the source string's length is equal to the sizeof.

Fix by replacing strncpy with strlcpy that guarantees NULL-termination.

[merged several commits]

Coverty issue: 272606
Fixes: d75c371e9b46 ("examples/ip_pipeline: add pipeline object")
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Coverty issue: 272594
Fixes: 133c2c6565d6 ("examples/ip_pipeline: add link object")
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Coverty issue: 272603
Fixes: 2f74ae28e23f ("examples/ip_pipeline: add tap object")
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Coverity issue: 272588
Fixes: 6bfe74f8c93e ("examples/ip_pipeline: add mempool object")
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com>
Coverity issue: 272592
Fixes: 25961ff3bcb9 ("examples/ip_pipeline: add traffic manager object")
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com>
Coverity issue: 272562
Fixes: 9a408cc8ac ("examples/ip_pipeline: add KNI object")
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com>
Coverity issue: 272580
Fixes: 719374345c ("examples/ip_pipeline: add action profile objects")
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com>
Coverity issue: 272572
Fixes: 719374345cee ("examples/ip_pipeline: add action profile objects")
Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Coverity issue: 272563
Fixes: 8245472c58c8 ("examples/ip_pipeline: add sw queue object")
Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
examples/ip_pipeline/action.c
examples/ip_pipeline/kni.c
examples/ip_pipeline/link.c
examples/ip_pipeline/mempool.c
examples/ip_pipeline/pipeline.c
examples/ip_pipeline/swq.c
examples/ip_pipeline/tap.c
examples/ip_pipeline/tmgr.c

index 77a04fe..a29c2b3 100644 (file)
@@ -6,6 +6,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <rte_string_fns.h>
+
 #include "action.h"
 #include "hash_func.h"
 
@@ -133,7 +135,7 @@ port_in_action_profile_create(const char *name,
        }
 
        /* Node fill in */
-       strncpy(profile->name, name, sizeof(profile->name));
+       strlcpy(profile->name, name, sizeof(profile->name));
        memcpy(&profile->params, params, sizeof(*params));
        profile->ap = ap;
 
@@ -345,7 +347,7 @@ table_action_profile_create(const char *name,
        }
 
        /* Node fill in */
-       strncpy(profile->name, name, sizeof(profile->name));
+       strlcpy(profile->name, name, sizeof(profile->name));
        memcpy(&profile->params, params, sizeof(*params));
        profile->ap = ap;
 
index ed5f894..7e5ff05 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <rte_ethdev.h>
 #include <rte_bus_pci.h>
+#include <rte_string_fns.h>
 
 #include "kni.h"
 #include "mempool.h"
@@ -153,7 +154,7 @@ kni_create(const char *name, struct kni_params *params)
                return NULL;
 
        /* Node fill in */
-       strncpy(kni->name, name, sizeof(kni->name));
+       strlcpy(kni->name, name, sizeof(kni->name));
        kni->k = k;
 
        /* Node add to list */
index 26ff41b..b8a431f 100644 (file)
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include <rte_ethdev.h>
+#include <rte_string_fns.h>
 
 #include "link.h"
 #include "mempool.h"
@@ -236,7 +237,7 @@ link_create(const char *name, struct link_params *params)
        }
 
        /* Node fill in */
-       strncpy(link->name, name, sizeof(link->name));
+       strlcpy(link->name, name, sizeof(link->name));
        link->port_id = port_id;
        link->n_rxq = params->rx.n_queues;
        link->n_txq = params->tx.n_queues;
index 33b9243..f5d2a7d 100644 (file)
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include <rte_mbuf.h>
+#include <rte_string_fns.h>
 
 #include "mempool.h"
 
@@ -70,7 +71,7 @@ mempool_create(const char *name, struct mempool_params *params)
        }
 
        /* Node fill in */
-       strncpy(mempool->name, name, sizeof(mempool->name));
+       strlcpy(mempool->name, name, sizeof(mempool->name));
        mempool->m = m;
        mempool->buffer_size = params->buffer_size;
 
index 76aa1d3..43fe867 100644 (file)
@@ -9,6 +9,7 @@
 #include <rte_ip.h>
 #include <rte_tcp.h>
 
+#include <rte_string_fns.h>
 #include <rte_port_ethdev.h>
 #ifdef RTE_LIBRTE_KNI
 #include <rte_port_kni.h>
@@ -129,7 +130,7 @@ pipeline_create(const char *name, struct pipeline_params *params)
        }
 
        /* Node fill in */
-       strncpy(pipeline->name, name, sizeof(pipeline->name));
+       strlcpy(pipeline->name, name, sizeof(pipeline->name));
        pipeline->p = p;
        pipeline->n_ports_in = 0;
        pipeline->n_ports_out = 0;
index c11bbf2..7e54a1d 100644 (file)
@@ -5,6 +5,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <rte_string_fns.h>
+
 #include "swq.h"
 
 static struct swq_list swq_list;
@@ -64,7 +66,7 @@ swq_create(const char *name, struct swq_params *params)
        }
 
        /* Node fill in */
-       strncpy(swq->name, name, sizeof(swq->name));
+       strlcpy(swq->name, name, sizeof(swq->name));
        swq->r = r;
 
        /* Node add to list */
index a0f6086..11e4ad2 100644 (file)
@@ -15,6 +15,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <rte_string_fns.h>
+
 #include "tap.h"
 
 #define TAP_DEV                                            "/dev/net/tun"
@@ -88,7 +90,7 @@ tap_create(const char *name)
                return NULL;
        }
        /* Node fill in */
-       strncpy(tap->name, name, sizeof(tap->name));
+       strlcpy(tap->name, name, sizeof(tap->name));
        tap->fd = fd;
 
        /* Node add to list */
index b46ca96..40cbf1d 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <stdlib.h>
 
+#include <rte_string_fns.h>
+
 #include "tmgr.h"
 
 static struct rte_sched_subport_params
@@ -148,7 +150,7 @@ tmgr_port_create(const char *name, struct tmgr_port_params *params)
        }
 
        /* Node fill in */
-       strncpy(tmgr_port->name, name, sizeof(tmgr_port->name));
+       strlcpy(tmgr_port->name, name, sizeof(tmgr_port->name));
        tmgr_port->s = s;
        tmgr_port->n_subports_per_port = params->n_subports_per_port;
        tmgr_port->n_pipes_per_subport = params->n_pipes_per_subport;