From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bruce Richardson Subject: Re: [PATCH 2/5] example_ip_pipeline: avoid strncpy issue Date: Thu, 10 Sep 2015 09:44:03 +0100 Message-ID: <20150910084403.GA25956@bricha3-MOBL3> References: <1441072746-29174-1-git-send-email-stephen@networkplumber.org> <1441072746-29174-3-git-send-email-stephen@networkplumber.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: dev@dpdk.org To: Stephen Hemminger Return-path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 138C1952 for ; Thu, 10 Sep 2015 10:44:07 +0200 (CEST) Content-Disposition: inline In-Reply-To: <1441072746-29174-3-git-send-email-stephen@networkplumber.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Mon, Aug 31, 2015 at 06:59:03PM -0700, Stephen Hemminger wrote: > If name is so long that it fills buffer, then string would not > be null terminated. > > Signed-off-by: Stephen Hemminger > --- > examples/ip_pipeline/config_parse_tm.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/examples/ip_pipeline/config_parse_tm.c b/examples/ip_pipeline/config_parse_tm.c > index 84702b0..4a35715 100644 > --- a/examples/ip_pipeline/config_parse_tm.c > +++ b/examples/ip_pipeline/config_parse_tm.c > @@ -354,7 +354,9 @@ tm_cfgfile_load_sched_subport( > profile = atoi(entries[j].value); > strncpy(name, > entries[j].name, > - sizeof(name)); > + CFG_NAME_LEN - 1); > + name[CFG_NAME_LEN-1] = '\0'; > + > n_tokens = rte_strsplit( > &name[sizeof("pipe")], > strnlen(name, CFG_NAME_LEN), > -- > 2.1.4 > Would using snprintf rather than strncpy be tidier? Would save having to worry about null termination at all. /Bruce