Message ID | 20220405062403.22591-1-ytcoode@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | [bpf-next,v2] selftests/bpf: Fix issues in parse_num_list() | expand |
Context | Check | Description |
---|---|---|
bpf/vmtest-bpf-next-PR | success | PR summary |
netdev/tree_selection | success | Clearly marked for bpf-next |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/subject_prefix | success | Link |
netdev/cover_letter | success | Single patches do not need cover letters |
netdev/patch_count | success | Link |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/cc_maintainers | success | CCed 12 of 12 maintainers |
netdev/build_clang | success | Errors and warnings before: 0 this patch: 0 |
netdev/module_param | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/verify_fixes | success | No Fixes tag |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 32 lines checked |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
On Mon, Apr 4, 2022 at 11:24 PM Yuntao Wang <ytcoode@gmail.com> wrote: > > 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 <ytcoode@gmail.com> > --- > v1 -> v2: add more details to commit message > > tools/testing/selftests/bpf/testing_helpers.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c > index 795b6798ccee..82f0e2d99c23 100644 > --- a/tools/testing/selftests/bpf/testing_helpers.c > +++ b/tools/testing/selftests/bpf/testing_helpers.c > @@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) > if (errno) > return -errno; > > - if (parsing_end) > - end = num; > - else > + if (!parsing_end) { > start = num; > + if (*next == '-') { > + s = next + 1; > + parsing_end = true; > + continue; > + } > + } > > - if (!parsing_end && *next == '-') { > - s = next + 1; > - parsing_end = true; > - continue; > - } else if (*next == ',') { I think the new structure of the code is actually harder to follow and there is no need to change this code in the first place just to optimize away parsing_end assignmet. > + if (*next == ',') { > parsing_end = false; > s = next + 1; > end = num; > @@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) > set[i] = true; > } > > - if (!set) > + if (!set || parsing_end) > return -EINVAL; > this is a real fix, please submit just and drop the first part of the patch > *num_set = set; > -- > 2.35.1 >
diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c index 795b6798ccee..82f0e2d99c23 100644 --- a/tools/testing/selftests/bpf/testing_helpers.c +++ b/tools/testing/selftests/bpf/testing_helpers.c @@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) if (errno) return -errno; - if (parsing_end) - end = num; - else + if (!parsing_end) { start = num; + if (*next == '-') { + s = next + 1; + parsing_end = true; + continue; + } + } - if (!parsing_end && *next == '-') { - s = next + 1; - parsing_end = true; - continue; - } else if (*next == ',') { + if (*next == ',') { parsing_end = false; s = next + 1; end = num; @@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) set[i] = true; } - if (!set) + if (!set || parsing_end) return -EINVAL; *num_set = set;
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 <ytcoode@gmail.com> --- v1 -> v2: add more details to commit message tools/testing/selftests/bpf/testing_helpers.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)