From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.warmcat.com (mail.warmcat.com [163.172.24.82]) by dpdk.org (Postfix) with ESMTP id 21B664C71 for ; Tue, 8 May 2018 07:10:31 +0200 (CEST) From: Andy Green To: dev@dpdk.org Date: Tue, 08 May 2018 12:30:38 +0800 Message-ID: <152575383848.56689.2292162671048307174.stgit@localhost.localdomain> In-Reply-To: <152575364588.56689.3300796065057551728.stgit@localhost.localdomain> References: <152575364588.56689.3300796065057551728.stgit@localhost.localdomain> User-Agent: StGit/unknown-version Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [dpdk-dev] [PATCH 14/18] drivers: net: vdev: fix 3 x strncpy misuse 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: Tue, 08 May 2018 05:10:31 -0000 --- drivers/net/vdev_netvsc/vdev_netvsc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/vdev_netvsc/vdev_netvsc.c b/drivers/net/vdev_netvsc/vdev_netvsc.c index c11794137..c36ec0f9a 100644 --- a/drivers/net/vdev_netvsc/vdev_netvsc.c +++ b/drivers/net/vdev_netvsc/vdev_netvsc.c @@ -182,7 +182,8 @@ vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface, is_netvsc_ret = vdev_netvsc_iface_is_netvsc(&iface[i]) ? 1 : 0; if (is_netvsc ^ is_netvsc_ret) continue; - strncpy(req.ifr_name, iface[i].if_name, sizeof(req.ifr_name)); + strncpy(req.ifr_name, iface[i].if_name, sizeof(req.ifr_name) - 1); + req.ifr_name[sizeof(req.ifr_name) - 1] = '\0'; if (ioctl(s, SIOCGIFHWADDR, &req) == -1) { DRV_LOG(WARNING, "cannot retrieve information about" " interface \"%s\": %s", @@ -383,7 +384,8 @@ vdev_netvsc_device_probe(const struct if_nameindex *iface, DRV_LOG(DEBUG, "NetVSC interface \"%s\" (index %u) renamed \"%s\"", ctx->if_name, ctx->if_index, iface->if_name); - strncpy(ctx->if_name, iface->if_name, sizeof(ctx->if_name)); + strncpy(ctx->if_name, iface->if_name, sizeof(ctx->if_name) - 1); + ctx->if_name[sizeof(ctx->if_name) - 1] = '\0'; return 0; } if (!is_same_ether_addr(eth_addr, &ctx->if_addr)) @@ -581,7 +583,8 @@ vdev_netvsc_netvsc_probe(const struct if_nameindex *iface, goto error; } ctx->id = vdev_netvsc_ctx_count; - strncpy(ctx->if_name, iface->if_name, sizeof(ctx->if_name)); + strncpy(ctx->if_name, iface->if_name, sizeof(ctx->if_name) - 1); + ctx->if_name[sizeof(ctx->if_name) - 1] = '\0'; ctx->if_index = iface->if_index; ctx->if_addr = *eth_addr; ctx->pipe[0] = -1;