From patchwork Wed May 9 15:56:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pattan, Reshma" X-Patchwork-Id: 39627 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8031A1B1BC; Wed, 9 May 2018 17:57:04 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id B5D261B020; Wed, 9 May 2018 17:57:02 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 08:57:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,382,1520924400"; d="scan'208";a="47943641" Received: from sivswdev02.ir.intel.com (HELO localhost.localdomain) ([10.237.217.46]) by FMSMGA003.fm.intel.com with ESMTP; 09 May 2018 08:56:59 -0700 From: Reshma Pattan To: dev@dpdk.org Cc: bruce.richardson@intel.com, stable@dpdk.org, "Zhang,Roy Fan" , Reshma Pattan Date: Wed, 9 May 2018 16:56:57 +0100 Message-Id: <1525881417-30440-1-git-send-email-reshma.pattan@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1525865729-16086-1-git-send-email-reshma.pattan@intel.com> References: <1525865729-16086-1-git-send-email-reshma.pattan@intel.com> Subject: [dpdk-dev] [PATCH v2] examples/ipsec-secgw: replace strncpy with strlcpy X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Use strlcpy instead of strncpy. Use strcpy where boundchecks on destination is not needed. Fixes: 0d547ed037 ("examples/ipsec-secgw: support configuration file") Fixes: 07b156199f ("examples/ipsec-secgw: fix configuration string termination") Fixes: a1469c319f ("examples/ipsec-secgw: fix configuration parsing") Cc: stable@dpdk.org CC: Zhang,Roy Fan Signed-off-by: Reshma Pattan --- v2: use destination based boundary checks in strlcpy. --- examples/ipsec-secgw/parser.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/ipsec-secgw/parser.c b/examples/ipsec-secgw/parser.c index 2403b564d..2a669a6ad 100644 --- a/examples/ipsec-secgw/parser.c +++ b/examples/ipsec-secgw/parser.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #include @@ -207,19 +208,20 @@ inet_pton6(const char *src, unsigned char *dst) int parse_ipv4_addr(const char *token, struct in_addr *ipv4, uint32_t *mask) { - char ip_str[256] = {0}; + char ip_str[INET_ADDRSTRLEN] = {0}; char *pch; pch = strchr(token, '/'); if (pch != NULL) { - strncpy(ip_str, token, pch - token); + strlcpy(ip_str, token, RTE_MIN((long unsigned int)(pch - token), + sizeof(ip_str))); pch += 1; if (is_str_num(pch) != 0) return -EINVAL; if (mask) *mask = atoi(pch); } else { - strncpy(ip_str, token, sizeof(ip_str) - 1); + strlcpy(ip_str, token, sizeof(ip_str)); if (mask) *mask = 0; } @@ -241,14 +243,15 @@ parse_ipv6_addr(const char *token, struct in6_addr *ipv6, uint32_t *mask) pch = strchr(token, '/'); if (pch != NULL) { - strncpy(ip_str, token, pch - token); + strlcpy(ip_str, token, RTE_MIN((long unsigned int)(pch - token), + sizeof(ip_str))); pch += 1; if (is_str_num(pch) != 0) return -EINVAL; if (mask) *mask = atoi(pch); } else { - strncpy(ip_str, token, sizeof(ip_str) - 1); + strlcpy(ip_str, token, sizeof(ip_str)); if (mask) *mask = 0; } @@ -515,9 +518,7 @@ parse_cfg_file(const char *cfg_filename) goto error_exit; } - strncpy(str + strlen(str), oneline, - strlen(oneline)); - + strcpy(str + strlen(str), oneline); continue; } @@ -528,8 +529,7 @@ parse_cfg_file(const char *cfg_filename) cfg_filename, line_num); goto error_exit; } - strncpy(str + strlen(str), oneline, - strlen(oneline)); + strcpy(str + strlen(str), oneline); str[strlen(str)] = '\n'; if (cmdline_parse(cl, str) < 0) {