Skip to content

Commit 3b5019f

Browse files
ytcoodeNobody
authored andcommitted
selftests/bpf: Fix issues in parse_num_list()
There are some issues in parse_num_list(): First, the end variable is assigned twice when parsing_end is true, it is unnecessary. Second, the function does not check that parsing_end is false after parsing argument. Thus, if the final part of the argument is something like '4-', parse_num_list() will discard it instead of returning -EINVAL. Clean up parse_num_list() and fix these issues. Before: $ ./test_progs -n 2,4- #2 atomic_bounds:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED After: $ ./test_progs -n 2,4- Failed to parse test numbers. Signed-off-by: Yuntao Wang <[email protected]>
1 parent 7d859cf commit 3b5019f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tools/testing/selftests/bpf/testing_helpers.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len)
2020
if (errno)
2121
return -errno;
2222

23-
if (parsing_end)
24-
end = num;
25-
else
23+
if (!parsing_end) {
2624
start = num;
25+
if (*next == '-') {
26+
s = next + 1;
27+
parsing_end = true;
28+
continue;
29+
}
30+
}
2731

28-
if (!parsing_end && *next == '-') {
29-
s = next + 1;
30-
parsing_end = true;
31-
continue;
32-
} else if (*next == ',') {
32+
if (*next == ',') {
3333
parsing_end = false;
3434
s = next + 1;
3535
end = num;
@@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len)
6060
set[i] = true;
6161
}
6262

63-
if (!set)
63+
if (!set || parsing_end)
6464
return -EINVAL;
6565

6666
*num_set = set;

0 commit comments

Comments
 (0)