linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Yuntao Wang <ytcoode@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH bpf-next] selftests/bpf: Fix issues in parse_num_list()
Date: Mon, 4 Apr 2022 15:12:13 -0700	[thread overview]
Message-ID: <CAEf4BzZrc=wr4FLkWkOSEeprzybA8JTipsnr_U1kYA0785WkTw@mail.gmail.com> (raw)
In-Reply-To: <20220404164514.1814897-1-ytcoode@gmail.com>

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
>

  reply	other threads:[~2022-04-04 22:53 UTC|newest]

Thread overview: 4+ 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 [this message]
2022-04-05  6:24   ` [PATCH bpf-next v2] " Yuntao Wang
2022-04-05 23:28     ` Andrii Nakryiko

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='CAEf4BzZrc=wr4FLkWkOSEeprzybA8JTipsnr_U1kYA0785WkTw@mail.gmail.com' \
    --to=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 \
    --cc=ytcoode@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).