[2/2] eal: fix service core index validity
Checks
Commit Message
From: Chengwen Feng <fengchengwen@huawei.com>
This patch adds checking for service core index validity when parsing
service corelist.
Fixes: 7dbd7a6413ef ("service: add -S corelist option")
Cc: stable@dpdk.org
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
lib/librte_eal/common/eal_common_options.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On Wed, 21 Apr 2021 09:17:17 +0800
"Min Hu (Connor)" <humin29@huawei.com> wrote:
> idx = strtoul(corelist, &end, 10);
> if (errno || end == NULL)
> return -1;
> + if (idx < 0 || idx >= RTE_MAX_LCORE)
Wondered at first how strtoul() could ever return an negative value but then
noticed that idx is int here.
The code that does would be clearer and safer if the variables were an unsigned
type. idx, min, max should be the same type everywhere.
Looks like the original code was written in old C style of "all the world's an int"
Hi, fixed in v2, thanks.
在 2021/4/21 10:33, Stephen Hemminger 写道:
> On Wed, 21 Apr 2021 09:17:17 +0800
> "Min Hu (Connor)" <humin29@huawei.com> wrote:
>
>> idx = strtoul(corelist, &end, 10);
>> if (errno || end == NULL)
>> return -1;
>> + if (idx < 0 || idx >= RTE_MAX_LCORE)
>
> Wondered at first how strtoul() could ever return an negative value but then
> noticed that idx is int here.
>
> The code that does would be clearer and safer if the variables were an unsigned
> type. idx, min, max should be the same type everywhere.
>
> Looks like the original code was written in old C style of "all the world's an int"
> .
>
@@ -785,6 +785,8 @@ eal_parse_service_corelist(const char *corelist)
idx = strtoul(corelist, &end, 10);
if (errno || end == NULL)
return -1;
+ if (idx < 0 || idx >= RTE_MAX_LCORE)
+ return -1;
while (isblank(*end))
end++;
if (*end == '-') {