From patchwork Wed Sep 28 19:20:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "John W. Linville" X-Patchwork-Id: 16200 X-Patchwork-Delegate: bruce.richardson@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 07F5C5683; Wed, 28 Sep 2016 21:30:16 +0200 (CEST) Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id DAD8F567A for ; Wed, 28 Sep 2016 21:30:14 +0200 (CEST) Received: from uucp by smtp.tuxdriver.com with local-rmail (Exim 4.63) (envelope-from ) id 1bpKYX-0000Pi-K2 for dev@dpdk.org; Wed, 28 Sep 2016 15:30:13 -0400 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.15.2/8.14.6) with ESMTP id u8SJK9Ua020760 for ; Wed, 28 Sep 2016 15:20:09 -0400 Received: (from linville@localhost) by localhost.localdomain (8.15.2/8.15.2/Submit) id u8SJK9FM020759 for dev@dpdk.org; Wed, 28 Sep 2016 15:20:09 -0400 X-Authentication-Warning: localhost.localdomain: linville set sender to linville@tuxdriver.com using -f From: "John W. Linville" To: dev@dpdk.org Date: Wed, 28 Sep 2016 15:20:01 -0400 Message-Id: <1475090404-20707-2-git-send-email-linville@tuxdriver.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475090404-20707-1-git-send-email-linville@tuxdriver.com> References: <1475090404-20707-1-git-send-email-linville@tuxdriver.com> Subject: [dpdk-dev] [PATCH 1/4] ena_config_host_info: improve safety of string handling 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Use sizeof dest rather than sizeof src for limiting copy length, and replace strncpy with snprintf to ensure NULL termination. Coverity: 127795 Signed-off-by: John W. Linville --- drivers/net/ena/ena_ethdev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index d106f5f39dce..649cb17d4a06 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -342,11 +342,13 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev) host_info->os_type = ENA_ADMIN_OS_DPDK; host_info->kernel_ver = RTE_VERSION; - strncpy((char *)host_info->kernel_ver_str, rte_version(), - strlen(rte_version())); + snprintf((char *)host_info->kernel_ver_str, + sizeof(host_info->kernel_ver_str), + "%s", rte_version()); host_info->os_dist = RTE_VERSION; - strncpy((char *)host_info->os_dist_str, rte_version(), - strlen(rte_version())); + snprintf((char *)host_info->os_dist_str, + sizeof(host_info->os_dist_str), + "%s", rte_version()); host_info->driver_version = (DRV_MODULE_VER_MAJOR) | (DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |