From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hari kumar Vemula Subject: [PATCH v2] eal: fix core number validation Date: Thu, 3 Jan 2019 12:28:07 +0000 Message-ID: <1546518487-9942-1-git-send-email-hari.kumarx.vemula@intel.com> References: Cc: stable@dpdk.org, reshma.pattan@intel.com, ferruh.yigit@intel.com, david.marchand@redhat.com, jananeex.m.parthasarathy@intel.com, Hari kumar Vemula To: dev@dpdk.org Return-path: In-Reply-To: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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