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: sta...@dpdk.org -- v2: Replace strtoul with strtol Modified log message -- Signed-off-by: Hari kumar Vemula <hari.kumarx.vem...@intel.com> --- 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