From 7959831b4d1b52f6525acb63ce0d94eeeb396855 Mon Sep 17 00:00:00 2001 From: Jasvinder Singh Date: Tue, 17 Apr 2018 14:17:19 +0100 Subject: [PATCH] examples/ip_pipeline: replace strncpy with strlcpy 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 Acked-by: Bruce Richardson Coverty issue: 272594 Fixes: 133c2c6565d6 ("examples/ip_pipeline: add link object") Signed-off-by: Jasvinder Singh Coverty issue: 272603 Fixes: 2f74ae28e23f ("examples/ip_pipeline: add tap object") Signed-off-by: Jasvinder Singh Acked-by: Bruce Richardson Coverity issue: 272588 Fixes: 6bfe74f8c93e ("examples/ip_pipeline: add mempool object") Signed-off-by: Kevin Laatz Reviewed-by: Jasvinder Singh Coverity issue: 272592 Fixes: 25961ff3bcb9 ("examples/ip_pipeline: add traffic manager object") Signed-off-by: Kevin Laatz Reviewed-by: Jasvinder Singh Coverity issue: 272562 Fixes: 9a408cc8ac ("examples/ip_pipeline: add KNI object") Signed-off-by: Reshma Pattan Reviewed-by: Jasvinder Singh Coverity issue: 272580 Fixes: 719374345c ("examples/ip_pipeline: add action profile objects") Signed-off-by: Reshma Pattan Reviewed-by: Jasvinder Singh Coverity issue: 272572 Fixes: 719374345cee ("examples/ip_pipeline: add action profile objects") Signed-off-by: Fan Zhang Acked-by: Bruce Richardson Coverity issue: 272563 Fixes: 8245472c58c8 ("examples/ip_pipeline: add sw queue object") Signed-off-by: Fan Zhang Acked-by: Bruce Richardson --- examples/ip_pipeline/action.c | 6 ++++-- examples/ip_pipeline/kni.c | 3 ++- examples/ip_pipeline/link.c | 3 ++- examples/ip_pipeline/mempool.c | 3 ++- examples/ip_pipeline/pipeline.c | 3 ++- examples/ip_pipeline/swq.c | 4 +++- examples/ip_pipeline/tap.c | 4 +++- examples/ip_pipeline/tmgr.c | 4 +++- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/examples/ip_pipeline/action.c b/examples/ip_pipeline/action.c index 77a04fe19d..a29c2b368f 100644 --- a/examples/ip_pipeline/action.c +++ b/examples/ip_pipeline/action.c @@ -6,6 +6,8 @@ #include #include +#include + #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; diff --git a/examples/ip_pipeline/kni.c b/examples/ip_pipeline/kni.c index ed5f8942e2..7e5ff0543a 100644 --- a/examples/ip_pipeline/kni.c +++ b/examples/ip_pipeline/kni.c @@ -7,6 +7,7 @@ #include #include +#include #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 */ diff --git a/examples/ip_pipeline/link.c b/examples/ip_pipeline/link.c index 26ff41ba9c..b8a431f3e0 100644 --- a/examples/ip_pipeline/link.c +++ b/examples/ip_pipeline/link.c @@ -6,6 +6,7 @@ #include #include +#include #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; diff --git a/examples/ip_pipeline/mempool.c b/examples/ip_pipeline/mempool.c index 33b9243397..f5d2a7d108 100644 --- a/examples/ip_pipeline/mempool.c +++ b/examples/ip_pipeline/mempool.c @@ -6,6 +6,7 @@ #include #include +#include #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; diff --git a/examples/ip_pipeline/pipeline.c b/examples/ip_pipeline/pipeline.c index 76aa1d3a9a..43fe8677a5 100644 --- a/examples/ip_pipeline/pipeline.c +++ b/examples/ip_pipeline/pipeline.c @@ -9,6 +9,7 @@ #include #include +#include #include #ifdef RTE_LIBRTE_KNI #include @@ -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; diff --git a/examples/ip_pipeline/swq.c b/examples/ip_pipeline/swq.c index c11bbf27e3..7e54a1dbfe 100644 --- a/examples/ip_pipeline/swq.c +++ b/examples/ip_pipeline/swq.c @@ -5,6 +5,8 @@ #include #include +#include + #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 */ diff --git a/examples/ip_pipeline/tap.c b/examples/ip_pipeline/tap.c index a0f60867f7..11e4ad20e2 100644 --- a/examples/ip_pipeline/tap.c +++ b/examples/ip_pipeline/tap.c @@ -15,6 +15,8 @@ #include #include +#include + #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 */ diff --git a/examples/ip_pipeline/tmgr.c b/examples/ip_pipeline/tmgr.c index b46ca96db2..40cbf1d0a2 100644 --- a/examples/ip_pipeline/tmgr.c +++ b/examples/ip_pipeline/tmgr.c @@ -4,6 +4,8 @@ #include +#include + #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; -- 2.20.1