From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 03BE1A0471 for ; Fri, 21 Jun 2019 18:49:24 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EE8BD5B3A; Fri, 21 Jun 2019 18:49:23 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id E72461D56A for ; Fri, 21 Jun 2019 18:49:21 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FF9F87620; Fri, 21 Jun 2019 16:49:13 +0000 (UTC) Received: from rh.redhat.com (ovpn-117-77.ams2.redhat.com [10.36.117.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0129E60FAB; Fri, 21 Jun 2019 16:49:08 +0000 (UTC) From: Kevin Traynor To: Michael Santana Cc: Bruce Richardson , Anatoly Burakov , dpdk stable Date: Fri, 21 Jun 2019 17:45:59 +0100 Message-Id: <20190621164626.31219-15-ktraynor@redhat.com> In-Reply-To: <20190621164626.31219-1-ktraynor@redhat.com> References: <20190621164626.31219-1-ktraynor@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 21 Jun 2019 16:49:21 +0000 (UTC) Subject: [dpdk-stable] patch 'fix off-by-one errors in snprintf' has been queued to LTS release 18.11.3 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 18.11.3 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 06/26/19. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/5eb73b34f8167cd001eee415893554c3c2bc6168 Thanks. Kevin Traynor --- >From 5eb73b34f8167cd001eee415893554c3c2bc6168 Mon Sep 17 00:00:00 2001 From: Michael Santana Date: Fri, 10 May 2019 10:53:12 -0400 Subject: [PATCH] fix off-by-one errors in snprintf [ upstream commit f4be6a9a2903e68f5f04124eeb59325c17f1e1eb ] snprintf guarantees to always correctly place a null terminator in the buffer string. So manually placing a null terminator in a buffer right after a call to snprintf is redundant code. Additionally, there is no need to use 'sizeof(buffer) - 1' in snprintf as this means we are not using the last character in the buffer. 'sizeof(buffer)' is enough. Signed-off-by: Michael Santana Acked-by: Bruce Richardson Acked-by: Anatoly Burakov --- drivers/net/qede/base/bcm_osal.c | 4 ++-- drivers/net/qede/qede_filter.c | 2 +- drivers/net/vdev_netvsc/vdev_netvsc.c | 2 +- examples/multi_process/client_server_mp/shared/common.h | 2 +- examples/server_node_efd/shared/common.h | 2 +- lib/librte_eal/common/eal_common_options.c | 3 +-- lib/librte_eal/common/eal_filesystem.h | 9 ++++----- lib/librte_eal/common/malloc_heap.c | 4 ++-- 8 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/net/qede/base/bcm_osal.c b/drivers/net/qede/base/bcm_osal.c index 693328f11..9915df44f 100644 --- a/drivers/net/qede/base/bcm_osal.c +++ b/drivers/net/qede/base/bcm_osal.c @@ -129,5 +129,5 @@ void *osal_dma_alloc_coherent(struct ecore_dev *p_dev, OSAL_MEM_ZERO(mz_name, sizeof(*mz_name)); - snprintf(mz_name, sizeof(mz_name) - 1, "%lx", + snprintf(mz_name, sizeof(mz_name), "%lx", (unsigned long)rte_get_timer_cycles()); if (core_id == (unsigned int)LCORE_ID_ANY) @@ -168,5 +168,5 @@ void *osal_dma_alloc_coherent_aligned(struct ecore_dev *p_dev, OSAL_MEM_ZERO(mz_name, sizeof(*mz_name)); - snprintf(mz_name, sizeof(mz_name) - 1, "%lx", + snprintf(mz_name, sizeof(mz_name), "%lx", (unsigned long)rte_get_timer_cycles()); if (core_id == (unsigned int)LCORE_ID_ANY) diff --git a/drivers/net/qede/qede_filter.c b/drivers/net/qede/qede_filter.c index 5e6571ca6..0beade6d5 100644 --- a/drivers/net/qede/qede_filter.c +++ b/drivers/net/qede/qede_filter.c @@ -291,5 +291,5 @@ qede_config_arfs_filter(struct rte_eth_dev *eth_dev, * not currently used so it has no significance. */ - snprintf(mz_name, sizeof(mz_name) - 1, "%lx", + snprintf(mz_name, sizeof(mz_name), "%lx", (unsigned long)rte_get_timer_cycles()); mz = rte_memzone_reserve_aligned(mz_name, QEDE_MAX_FDIR_PKT_LEN, diff --git a/drivers/net/vdev_netvsc/vdev_netvsc.c b/drivers/net/vdev_netvsc/vdev_netvsc.c index a5fd64e0c..94d067b20 100644 --- a/drivers/net/vdev_netvsc/vdev_netvsc.c +++ b/drivers/net/vdev_netvsc/vdev_netvsc.c @@ -334,5 +334,5 @@ vdev_netvsc_sysfs_readlink(char *buf, size_t size, const char *if_name, int ret; - ret = snprintf(in, sizeof(in) - 1, "/sys/class/net/%s/%s", + ret = snprintf(in, sizeof(in), "/sys/class/net/%s/%s", if_name, relpath); if (ret == -1 || (size_t)ret >= sizeof(in)) diff --git a/examples/multi_process/client_server_mp/shared/common.h b/examples/multi_process/client_server_mp/shared/common.h index ac9175524..6dd43fcac 100644 --- a/examples/multi_process/client_server_mp/shared/common.h +++ b/examples/multi_process/client_server_mp/shared/common.h @@ -50,5 +50,5 @@ get_rx_queue_name(unsigned id) static char buffer[sizeof(MP_CLIENT_RXQ_NAME) + 2]; - snprintf(buffer, sizeof(buffer) - 1, MP_CLIENT_RXQ_NAME, id); + snprintf(buffer, sizeof(buffer), MP_CLIENT_RXQ_NAME, id); return buffer; } diff --git a/examples/server_node_efd/shared/common.h b/examples/server_node_efd/shared/common.h index b8b533d8c..130fd4f4e 100644 --- a/examples/server_node_efd/shared/common.h +++ b/examples/server_node_efd/shared/common.h @@ -62,5 +62,5 @@ get_rx_queue_name(unsigned int id) static char buffer[sizeof(MP_NODE_RXQ_NAME) + 2]; - snprintf(buffer, sizeof(buffer) - 1, MP_NODE_RXQ_NAME, id); + snprintf(buffer, sizeof(buffer), MP_NODE_RXQ_NAME, id); return buffer; } diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index d4ab5e235..79efb15d0 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -259,6 +259,5 @@ eal_plugindir_init(const char *path) struct stat sb; - snprintf(sopath, PATH_MAX-1, "%s/%s", path, dent->d_name); - sopath[PATH_MAX-1] = 0; + snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name); if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode))) diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h index 89a3added..aaba88e04 100644 --- a/lib/librte_eal/common/eal_filesystem.h +++ b/lib/librte_eal/common/eal_filesystem.h @@ -39,5 +39,5 @@ eal_runtime_config_path(void) static char buffer[PATH_MAX]; /* static so auto-zeroed */ - snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(), + snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), RUNTIME_CONFIG_FNAME); return buffer; @@ -51,5 +51,5 @@ eal_mp_socket_path(void) static char buffer[PATH_MAX]; /* static so auto-zeroed */ - snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(), + snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), MP_SOCKET_FNAME); return buffer; @@ -71,5 +71,5 @@ eal_hugepage_info_path(void) static char buffer[PATH_MAX]; /* static so auto-zeroed */ - snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(), + snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), HUGEPAGE_INFO_FNAME); return buffer; @@ -83,5 +83,5 @@ eal_hugepage_data_path(void) static char buffer[PATH_MAX]; /* static so auto-zeroed */ - snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(), + snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), HUGEPAGE_DATA_FNAME); return buffer; @@ -95,5 +95,4 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id snprintf(buffer, buflen, HUGEFILE_FMT, hugedir, eal_get_hugefile_prefix(), f_id); - buffer[buflen - 1] = '\0'; return buffer; } diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c index c6a6d4f6b..b8f26f2b3 100644 --- a/lib/librte_eal/common/malloc_heap.c +++ b/lib/librte_eal/common/malloc_heap.c @@ -1121,5 +1121,5 @@ malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, } - snprintf(fbarray_name, sizeof(fbarray_name) - 1, "%s_%p", + snprintf(fbarray_name, sizeof(fbarray_name), "%s_%p", heap->name, va_addr); @@ -1270,5 +1270,5 @@ rte_eal_malloc_heap_init(void) int socket_id = rte_socket_id_by_idx(i); - snprintf(heap_name, sizeof(heap_name) - 1, + snprintf(heap_name, sizeof(heap_name), "socket_%i", socket_id); strlcpy(heap->name, heap_name, RTE_HEAP_NAME_MAX_LEN); -- 2.20.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2019-06-21 17:22:12.527920053 +0100 +++ 0015-fix-off-by-one-errors-in-snprintf.patch 2019-06-21 17:22:11.727519035 +0100 @@ -1 +1 @@ -From f4be6a9a2903e68f5f04124eeb59325c17f1e1eb Mon Sep 17 00:00:00 2001 +From 5eb73b34f8167cd001eee415893554c3c2bc6168 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit f4be6a9a2903e68f5f04124eeb59325c17f1e1eb ] + @@ -14,2 +15,0 @@ -Cc: stable@dpdk.org - @@ -49 +49 @@ -index 7bdc3023f..fd4985861 100644 +index 5e6571ca6..0beade6d5 100644 @@ -60 +60 @@ -index ad13eac3b..edab63e3a 100644 +index a5fd64e0c..94d067b20 100644 @@ -63 +63 @@ -@@ -331,5 +331,5 @@ vdev_netvsc_sysfs_readlink(char *buf, size_t size, const char *if_name, +@@ -334,5 +334,5 @@ vdev_netvsc_sysfs_readlink(char *buf, size_t size, const char *if_name, @@ -93 +93 @@ -index 0c91024c4..512d5088e 100644 +index d4ab5e235..79efb15d0 100644 @@ -96 +96 @@ -@@ -261,6 +261,5 @@ eal_plugindir_init(const char *path) +@@ -259,6 +259,5 @@ eal_plugindir_init(const char *path) @@ -105 +105 @@ -index f2f83e712..5d21f07c2 100644 +index 89a3added..aaba88e04 100644 @@ -143 +143 @@ -index c5d254d8a..f9235932e 100644 +index c6a6d4f6b..b8f26f2b3 100644 @@ -146 +146 @@ -@@ -1119,5 +1119,5 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], +@@ -1121,5 +1121,5 @@ malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, @@ -151 +151 @@ - seg_name, va_addr); + heap->name, va_addr); @@ -153 +153 @@ -@@ -1335,5 +1335,5 @@ rte_eal_malloc_heap_init(void) +@@ -1270,5 +1270,5 @@ rte_eal_malloc_heap_init(void)