From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gaetan Rivet Subject: [PATCH] eal: fix off-by-one error in hotplug add Date: Fri, 4 Aug 2017 17:30:23 +0200 Message-ID: <1501860623-16747-1-git-send-email-gaetan.rivet@6wind.com> Cc: Gaetan Rivet To: dev@dpdk.org Return-path: Received: from mail-wr0-f169.google.com (mail-wr0-f169.google.com [209.85.128.169]) by dpdk.org (Postfix) with ESMTP id 2AF342C18 for ; Fri, 4 Aug 2017 17:30:38 +0200 (CEST) Received: by mail-wr0-f169.google.com with SMTP id y43so18102258wrd.3 for ; Fri, 04 Aug 2017 08:30:38 -0700 (PDT) List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" snprintf returns the length it would have written had the given length been enough, *terminating null byte excluded*. It will however limit the length of its writing to given length minus one, and always put a terminating null-byte at the end of the string. This must be taken into account when calculating the total length of the device declaration string. Fixes: 3054036f054a ("eal: fix possible crash in hotplug") Signed-off-by: Gaetan Rivet --- Charybdis -> Scylla lib/librte_eal/common/eal_common_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index fc8a4d2..e251275 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -133,7 +133,7 @@ full_dev_name(const char *bus, const char *dev, const char *args) char *name; size_t len; - len = snprintf(NULL, 0, "%s:%s,%s", bus, dev, args); + len = snprintf(NULL, 0, "%s:%s,%s", bus, dev, args) + 1; name = calloc(1, len); if (name == NULL) { RTE_LOG(ERR, EAL, "Could not allocate full device name\n"); -- 2.1.4