[PATCH 05/10] cmdline: fix port list parsing
David Marchand
david.marchand at redhat.com
Thu Jun 19 09:10:31 CEST 2025
Doing arithmetics 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>
---
lib/cmdline/cmdline_parse_portlist.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/cmdline/cmdline_parse_portlist.c b/lib/cmdline/cmdline_parse_portlist.c
index ef6ce223b5..0c07cc02b5 100644
--- a/lib/cmdline/cmdline_parse_portlist.c
+++ b/lib/cmdline/cmdline_parse_portlist.c
@@ -4,6 +4,7 @@
* All rights reserved.
*/
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -37,10 +38,11 @@ parse_ports(cmdline_portlist_t *pl, const char *str)
const char *first, *last;
char *end;
- for (first = str, last = first;
- first != NULL && last != NULL;
- first = last + 1) {
+ if (str == NULL)
+ return 0;
+ last = first = str;
+ do {
last = strchr(first, ',');
errno = 0;
@@ -65,7 +67,10 @@ parse_ports(cmdline_portlist_t *pl, const char *str)
return -1;
parse_set_list(pl, ps, pe);
- }
+ if (last == NULL)
+ break;
+ first = last + 1;
+ } while (true);
return 0;
}
--
2.49.0
More information about the dev
mailing list