All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuntao Wang <ytcoode@gmail.com>
To: andrii.nakryiko@gmail.com
Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org,
	daniel@iogearbox.net, john.fastabend@gmail.com, kafai@fb.com,
	kpsingh@kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
	shuah@kernel.org, songliubraving@fb.com, yhs@fb.com,
	ytcoode@gmail.com
Subject: [PATCH bpf-next v2] selftests/bpf: Fix issues in parse_num_list()
Date: Tue,  5 Apr 2022 14:24:03 +0800	[thread overview]
Message-ID: <20220405062403.22591-1-ytcoode@gmail.com> (raw)
In-Reply-To: <CAEf4BzZrc=wr4FLkWkOSEeprzybA8JTipsnr_U1kYA0785WkTw@mail.gmail.com>

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 == ',') {
+		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


  reply	other threads:[~2022-04-05  6:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 16:45 [PATCH bpf-next] selftests/bpf: Fix issues in parse_num_list() Yuntao Wang
2022-04-04 22:12 ` Andrii Nakryiko
2022-04-05  6:24   ` Yuntao Wang [this message]
2022-04-05 23:28     ` [PATCH bpf-next v2] " Andrii Nakryiko
2022-04-06  0:36       ` [PATCH bpf-next v3] " Yuntao Wang
2022-04-06 17:20         ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220405062403.22591-1-ytcoode@gmail.com \
    --to=ytcoode@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.