From mboxrd@z Thu Jan 1 00:00:00 1970 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=VKFZ642TONUPH/Hu7y5tv7Nr9HC7zOxxW4HAICPySks=; b=hALL2Qxiosr8xEUpJ4pFAQrs7ztl9QalZi/LAVdq1j9V2YUim42t6FGvGzcVIo18XM fDPHzOGtn5h0KKhTBWZkrdEjtKWriD59TQQrszxLYj3tV+R9HHZon///kzzj3qsM+GJe g3Hpckl9bssKNGGuqN3XMLGdfsRcuC4qFk7aD3zGQLIu+bnpHCgsYnn8sUfOof8R9Jgh NChSGvsPEK8+jR8mQTeq3usqeoLPNBhtyBS/k6HyUrSDW50kLf3A+LpuUJO0A//A7Q6q 4GLErKPYrLpIhTpwUXHysTn/5iYQTpXNKieY2WPm3qPawgXsKqnmHIAVKUBGcZQAH/W6 VUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VKFZ642TONUPH/Hu7y5tv7Nr9HC7zOxxW4HAICPySks=; b=FM720e+kGlN8GLlw+wYvXQwwF/fksccOY66O+pRwG7XtPPCk9x2zgwRdRXALpLIkDH YFs82vt2Da4MSIq9jaKZj9m4XC2ppXf2e7OrE6tSDsVK/XhOG7/GGsdwLAK9UvdnTy6l A4slhAKdf5q1TfkCjCJOfwc0oXcFJeZQwc06ioFSkbDmrLsgG+BJvhXzOuWEQPilnrAv o+uQ3NgpzgnTVD5lbUsbRUxR3m2nVhH6hx/GBnlIouthjEbSwPQmNOLVs123WL7+F2xd 9Cadnq+86zPr07OoxS4ELb9kYy2eBmUIVctawR++kybaB5JXH02pxEH9ZI1plKDM3Gpa slNg== X-Gm-Message-State: AIVw110ucD6owR+dmxWKwkKx9JhWX1RmNlpKNEQjpf+3S8e6n0GKN2Cg 2DoEKkHB1W9JrByRaeU= X-Received: by 10.223.176.148 with SMTP id i20mr1814209wra.165.1501860637451; Fri, 04 Aug 2017 08:30:37 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id j137sm6385683wmf.43.2017.08.04.08.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Aug 2017 08:30:36 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Fri, 4 Aug 2017 17:30:23 +0200 Message-Id: <1501860623-16747-1-git-send-email-gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH] eal: fix off-by-one error in hotplug add 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: Fri, 04 Aug 2017 15:30:38 -0000 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