From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f179.google.com (mail-wr0-f179.google.com [209.85.128.179]) by dpdk.org (Postfix) with ESMTP id 0B0EC2C55 for ; Thu, 3 Aug 2017 14:34:34 +0200 (CEST) Received: by mail-wr0-f179.google.com with SMTP id 33so5152013wrz.4 for ; Thu, 03 Aug 2017 05:34:34 -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=iZTKTs1cnUZTBPGb3QSIu7YVq4nLc9XLdej3BCk7VKQ=; b=OZS4vWRBlW5PTf6ORQOjQKTNtdoOE01PFbSQ1mi+C892UpSpFJx3y6OS42HaSl/jL9 +ywbDLbxs0Dkel4S9Y0N3kTZLM+sXBYGsGF9x2Zd9W6GcnbFJnMKLpNGwS6GgdrcO817 9h3B0HOczC4SfRZr/Cx88YAovT6vplbtX1JeCTxwOvfO1UzSt0zVcnDPnXMv5yPFTtk+ goVj40u8Wv5Ab91ToHCdvJbYTG/zZvbM0MW6YJNL8CcKtmh1QhtLGtyXbSvczZQPlCO/ ppknzmznW4S9FSeLSlZpwJvpSPd1nrgCH8ozUjmw+94w/23l6SX4CR/PFgmT9HZLhIqQ UBNg== 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=iZTKTs1cnUZTBPGb3QSIu7YVq4nLc9XLdej3BCk7VKQ=; b=eeGYMkbsP2SV12NhHn5sUL7GyVCyGONothPNBhOYNlV/ShU27WM2UVfgVjFi7avOZ/ ei0zFER87y7PZNwBIv1ZCsJ9Aon2qoKyilX2NUUPS350mSydp4lRnpOUGtD0InK1pDow L1HiErjgj4OPCNPch4l2QXWitwgIRZnRdpC/ZadSZyooezXsOivY9icw5tT9r4AFQ7lE psF4bZwu9DCBxswTNeu2etlBDmeaGfpxEWBcZScwWpQY4TJxPOeWMEiILNjq21B0jKy4 fZa2Ce+xSQi8byzxXJPX+tT8trXp+S5GHzYbNeYLXU1B9H1s5EJRwje0BDmzcLhhcZWf KnlA== X-Gm-Message-State: AIVw112W6gNyWNsVb8R5+B+whkD+6aEIGUDQ2z7tHnbDuvIErAniqUak IKj2tAAuoVlTnupvjR8= X-Received: by 10.223.170.2 with SMTP id p2mr1435876wrd.22.1501763674297; Thu, 03 Aug 2017 05:34:34 -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 c16sm1621015wmh.41.2017.08.03.05.34.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Aug 2017 05:34:33 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 3 Aug 2017 14:34:19 +0200 Message-Id: <31be1706d1613adecd43328272f1b6f556c6110f.1501763608.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH] eal: fix possible segfault 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: Thu, 03 Aug 2017 12:34:35 -0000 If devargs is NULL, building the full_dev_name will segfault when using strlen on it. Coverity issue: 158630 Fixes: 7e8b26650146 ("eal: fix hotplug add / remove") Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index f98302d..d19232d 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -133,16 +133,13 @@ full_dev_name(const char *bus, const char *dev, const char *args) char *name; size_t len; - len = strlen(bus) + 1 + - strlen(dev) + 1 + - strlen(args) + 1; + len = snprintf(NULL, 0, "%s:%s,%s", bus, dev, args); name = calloc(1, len); if (name == NULL) { RTE_LOG(ERR, EAL, "Could not allocate full device name\n"); return NULL; } - snprintf(name, len, "%s:%s,%s", bus, dev, - args ? args : ""); + snprintf(name, len, "%s:%s,%s", bus, dev, args); return name; } -- 2.1.4