From mboxrd@z Thu Jan 1 00:00:00 1970 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) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 10 Sep 2015 01:44:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,503,1437462000"; d="scan'208";a="786475633" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.220.172]) by fmsmga001.fm.intel.com with SMTP; 10 Sep 2015 01:44:05 -0700 Received: by (sSMTP sendmail emulation); Thu, 10 Sep 2015 09:44:04 +0025 Date: Thu, 10 Sep 2015 09:44:03 +0100 From: Bruce Richardson To: Stephen Hemminger 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 Content-Disposition: inline In-Reply-To: <1441072746-29174-3-git-send-email-stephen@networkplumber.org> Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH 2/5] example_ip_pipeline: avoid strncpy issue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Sep 2015 08:44:08 -0000 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