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 690E27CA2 for ; Thu, 4 May 2017 13:17:02 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 04 May 2017 04:17:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,287,1491289200"; d="scan'208";a="97155458" Received: from sivswdev02.ir.intel.com ([10.237.217.46]) by fmsmga005.fm.intel.com with ESMTP; 04 May 2017 04:17:01 -0700 From: Ferruh Yigit To: "John W. Linville" Cc: dev@dpdk.org, Ferruh Yigit , Chas Williams Date: Thu, 4 May 2017 12:16:59 +0100 Message-Id: <20170504111659.17670-1-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.8.4 Subject: [dpdk-dev] [PATCH] net/af_packet: prefer snprintf against strncpy 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: , X-List-Received-Date: Thu, 04 May 2017 11:17:03 -0000 strncpy may left destination buffer not NULL terminated, switched using snprintf to be sure destination buffer is NULL terminated. Coverity issue: 1407495 Coverity issue: 1407498 Fixes: cc68ac4847bc ("net/af_packet: support MTU change") Fixes: 218259590ea4 ("net/af_packet: support promiscuous") Signed-off-by: Ferruh Yigit --- Cc: Chas Williams --- drivers/net/af_packet/rte_eth_af_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 6f6ba0c..68de45c 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -452,7 +452,7 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) if (s < 0) return -EINVAL; - strncpy(ifr.ifr_name, internals->if_name, IFNAMSIZ); + snprintf(ifr.ifr_name, IFNAMSIZ, "%s", internals->if_name); ret = ioctl(s, SIOCSIFMTU, &ifr); close(s); @@ -472,7 +472,7 @@ eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask) if (s < 0) return; - strncpy(ifr.ifr_name, if_name, IFNAMSIZ); + snprintf(ifr.ifr_name, IFNAMSIZ, "%s", if_name); if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) goto out; ifr.ifr_flags &= mask; -- 2.9.3