[PATCH v4 05/22] cmdline: fix port list parsing
David Marchand
david.marchand at redhat.com
Wed Jul 16 15:01:52 CEST 2025
Doing arithmetic with the NULL pointer is undefined.
Caught by UBSan:
../lib/cmdline/cmdline_parse_portlist.c:40:19: runtime error:
applying non-zero offset 1 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../lib/cmdline/cmdline_parse_portlist.c:40:19 in
Fixes: af75078fece3 ("first public release")
Cc: stable at dpdk.org
Signed-off-by: David Marchand <david.marchand at redhat.com>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
Acked-by: Marat Khalili <marat.khalili at huawei.com>
---
Changes since v1:
- moved some variable as suggested by Bruce,
---
lib/cmdline/cmdline_parse_portlist.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/lib/cmdline/cmdline_parse_portlist.c b/lib/cmdline/cmdline_parse_portlist.c
index ef6ce223b5..549f6d9671 100644
--- a/lib/cmdline/cmdline_parse_portlist.c
+++ b/lib/cmdline/cmdline_parse_portlist.c
@@ -33,15 +33,12 @@ parse_set_list(cmdline_portlist_t *pl, size_t low, size_t high)
static int
parse_ports(cmdline_portlist_t *pl, const char *str)
{
+ const char *first = str;
size_t ps, pe;
- const char *first, *last;
char *end;
- for (first = str, last = first;
- first != NULL && last != NULL;
- first = last + 1) {
-
- last = strchr(first, ',');
+ while (first != NULL) {
+ const char *last = strchr(first, ',');
errno = 0;
ps = strtoul(first, &end, 10);
@@ -65,6 +62,7 @@ parse_ports(cmdline_portlist_t *pl, const char *str)
return -1;
parse_set_list(pl, ps, pe);
+ first = (last == NULL ? NULL : last + 1);
}
return 0;
--
2.50.0
More information about the dev
mailing list