diff mbox series

[bpf-next] selftests/bpf: Fix issues in parse_num_list()

Message ID 20220404164514.1814897-1-ytcoode@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: Fix issues in parse_num_list() | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR pending 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

Commit Message

Yuntao Wang April 4, 2022, 4:45 p.m. UTC
There are some issues in parse_num_list():

1. The end variable is assigned twice when parsing_end is true.
2. The function does not check that parsing_end should finally be false.

Clean up parse_num_list() and fix these issues.

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
 tools/testing/selftests/bpf/testing_helpers.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

Andrii Nakryiko April 4, 2022, 10:12 p.m. UTC | #1
On Mon, Apr 4, 2022 at 9:45 AM Yuntao Wang <ytcoode@gmail.com> wrote:
>
> There are some issues in parse_num_list():
>
> 1. The end variable is assigned twice when parsing_end is true.
> 2. The function does not check that parsing_end should finally be false.
>
> Clean up parse_num_list() and fix these issues.

It would be great to also explain user-visible bug. What do you do to
trigger bugs? Can you please put that into the commit message, in a
before/after fashion? Thanks!

>
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
>  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 == ',') {
> +               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;
> --
> 2.35.1
>
diff mbox series

Patch

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;