From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 5EC737CDA; Thu, 3 Jan 2019 13:28:43 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jan 2019 04:28:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,434,1539673200"; d="scan'208";a="307153954" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga006.fm.intel.com with ESMTP; 03 Jan 2019 04:28:41 -0800 Received: from wgcvswdev001.ir.intel.com (wgcvswdev001.ir.intel.com [10.102.246.100]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id x03CSfJw018596; Thu, 3 Jan 2019 12:28:41 GMT Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id x03CS92w010454; Thu, 3 Jan 2019 12:28:09 GMT Received: (from hvemulax@localhost) by wgcvswdev001.ir.intel.com with œ id x03CS9Hh010449; Thu, 3 Jan 2019 12:28:09 GMT From: Hari kumar Vemula To: dev@dpdk.org Cc: stable@dpdk.org, reshma.pattan@intel.com, ferruh.yigit@intel.com, david.marchand@redhat.com, jananeex.m.parthasarathy@intel.com, Hari kumar Vemula Date: Thu, 3 Jan 2019 12:28:07 +0000 Message-Id: <1546518487-9942-1-git-send-email-hari.kumarx.vemula@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: Subject: [dpdk-stable] [PATCH v2] eal: fix core number validation 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: , X-List-Received-Date: Thu, 03 Jan 2019 12:28:45 -0000 When incorrect core value or range provided, as part of -l command line option, a crash occurs. Added valid range checks to fix the crash. Fixes: d888cb8b9613 ("eal: add core list input format") Cc: stable@dpdk.org -- v2: Replace strtoul with strtol Modified log message -- Signed-off-by: Hari kumar Vemula --- lib/librte_eal/common/eal_common_options.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 6e3a83b98..b24668c23 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -592,7 +592,7 @@ eal_parse_corelist(const char *corelist) if (*corelist == '\0') return -1; errno = 0; - idx = strtoul(corelist, &end, 10); + idx = strtol(corelist, &end, 10); if (errno || end == NULL) return -1; while (isblank(*end)) @@ -603,6 +603,11 @@ eal_parse_corelist(const char *corelist) max = idx; if (min == RTE_MAX_LCORE) min = idx; + if ((unsigned int)idx >= cfg->lcore_count || + (unsigned int)min >= cfg->lcore_count) { + return -1; + } + for (idx = min; idx <= max; idx++) { if (cfg->lcore_role[idx] != ROLE_RTE) { cfg->lcore_role[idx] = ROLE_RTE; @@ -1103,6 +1108,7 @@ eal_parse_common_option(int opt, const char *optarg, { static int b_used; static int w_used; + struct rte_config *cfg = rte_eal_get_configuration(); switch (opt) { /* blacklist */ @@ -1145,7 +1151,9 @@ eal_parse_common_option(int opt, const char *optarg, /* corelist */ case 'l': if (eal_parse_corelist(optarg) < 0) { - RTE_LOG(ERR, EAL, "invalid core list\n"); + RTE_LOG(ERR, EAL, + "Invalid core number given core range should be(0, %u)\n", + cfg->lcore_count-1); return -1; } -- 2.17.2