From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id BDEE01E33 for ; Mon, 7 Nov 2016 15:21:08 +0100 (CET) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 07 Nov 2016 06:21:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,606,1473145200"; d="scan'208";a="28378598" Received: from sie-lab-212-071.ir.intel.com (HELO silpixa00381633.ir.intel.com) ([10.237.212.71]) by fmsmga005.fm.intel.com with ESMTP; 07 Nov 2016 06:21:06 -0800 From: Fan Zhang To: dev@dpdk.org Cc: sergio.gonzalez.monroy@intel.com Date: Mon, 7 Nov 2016 14:21:06 +0000 Message-Id: <1478528466-211016-1-git-send-email-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1478175163-229116-3-git-send-email-roy.fan.zhang@intel.com> References: <1478175163-229116-3-git-send-email-roy.fan.zhang@intel.com> Subject: [dpdk-dev] [PATCH v2] examples/ipsec-secgw: fix copy into fixed size buffer 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: Mon, 07 Nov 2016 14:21:10 -0000 Fixes: 0d547ed0 ("examples/ipsec-secgw: support configuration file") Coverity issue: 137875 Signed-off-by: Fan Zhang --- examples/ipsec-secgw/sa.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/ipsec-secgw/sa.c b/examples/ipsec-secgw/sa.c index 9e2c8a9..8c4406c 100644 --- a/examples/ipsec-secgw/sa.c +++ b/examples/ipsec-secgw/sa.c @@ -170,15 +170,18 @@ static uint32_t parse_key_string(const char *key_str, uint8_t *key) { const char *pt_start = key_str, *pt_end = key_str; - char sub_str[3]; uint32_t nb_bytes = 0; while (pt_end != NULL) { + char sub_str[3] = {0}; + pt_end = strchr(pt_start, ':'); - if (pt_end == NULL) - strncpy(sub_str, pt_start, strlen(pt_start)); - else { + if (pt_end == NULL) { + if (strlen(pt_start) > 2) + return 0; + strncpy(sub_str, pt_start, 2); + } else { if (pt_end - pt_start > 2) return 0; -- 2.5.5