diff mbox series

[2/2] eal: fix service core index validity

Message ID 1618967837-2341-3-git-send-email-humin29@huawei.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series fix bugs for librte eal | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/github-robot success github build: passed
ci/travis-robot success travis build: passed
ci/intel-Testing success Testing PASS
ci/iol-testing fail Testing issues
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Min Hu (Connor) April 21, 2021, 1:17 a.m. UTC
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

Stephen Hemminger April 21, 2021, 2:33 a.m. UTC | #1
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"
Min Hu (Connor) April 29, 2021, 2:34 a.m. UTC | #2
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"
> .
>
diff mbox series

Patch

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 66f9114..b4da878 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -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 == '-') {