From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D53CAC433EF for ; Wed, 6 Apr 2022 03:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1451508AbiDFDFm (ORCPT ); Tue, 5 Apr 2022 23:05:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1845804AbiDFCBU (ORCPT ); Tue, 5 Apr 2022 22:01:20 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BEF724B0B1; Tue, 5 Apr 2022 16:28:49 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id e22so1024084ioe.11; Tue, 05 Apr 2022 16:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PUMn2pJdmTqU9T1LboNHqySso6NmNTYjmvIQ/4E+6jg=; b=gNe8qsL51ziO0gB71BLSIYx0dhQmBI6zDUfVHVMAec4jf0pQWeA1zZ2h4sxZU8GVXA gwUULa+cnWQ/VxFgfOj97piyqAh4IFJLybVUZPOCK9XmdbSbzVB2zd3tGNBgypwj1rPh 9muXPJS+9ogRaxX9AaruMwEI28RqkVAL4VCFJBahhFKgRrqycnSZO67AiPJq57+Jg0hN rkbNi5jOgama1LtciEKjBZY0SR+ZZVR6qdmiR80UIKktan1Dvey1RiQ+ZlK3Zw+5Migj 3daCkrMJ2AETNxGIOuJDRDH2L7/CvWH+q99dqTdC3xZ0VlLhj0MZAV5UWFtqFqID5Lo2 fHvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PUMn2pJdmTqU9T1LboNHqySso6NmNTYjmvIQ/4E+6jg=; b=rN3eEdp/SYNWmwvXGfgmKmKZsRrv4BzKOFEm4SxYML0J3qPzFiMoipP6baKEfG1JbN upXHLesc1oJ8+1XZwwRz2gT5tos+y48BVwhvoQDkPSLOws9RJ9bpnjvQJ+xmVALREHxy pxhix35DWiagjAu6foNxRXriCmMitlmBJ1NkdgYx6SjOY8YiCfRV5QfSPasqypMOLdU9 7nIaWhU3sxAhUVE6EdLjsJw24eTUq7ZNBfkoDYoUbqmvF2N9TuyS8MVvQtYYA2wX0+/6 ehZXep5Eq2U721KJ/pgYk25qEtR71tl8QnJGStJcXMQ44GnCCWtBdj6qmd2N/rCCbnvI Btsg== X-Gm-Message-State: AOAM532HDWpEaATrBYEa+fP5TB21WjqzzdlZpzjVssOyoiV4qUE6oJ/j l3D439WzCFShQE4z7G2dTon4vGVGKfpmxD2dakw= X-Google-Smtp-Source: ABdhPJyKqUsGJx3oQJikLMMo7nQ3XQuZBU6aXhgu0HkBIbtVmBQTJNGbQwnmNfviladdps3TCxWYY7vRUoJCBgdNSMY= X-Received: by 2002:a6b:8bd7:0:b0:646:2804:5c73 with SMTP id n206-20020a6b8bd7000000b0064628045c73mr2711308iod.112.1649201328273; Tue, 05 Apr 2022 16:28:48 -0700 (PDT) MIME-Version: 1.0 References: <20220405062403.22591-1-ytcoode@gmail.com> In-Reply-To: <20220405062403.22591-1-ytcoode@gmail.com> From: Andrii Nakryiko Date: Tue, 5 Apr 2022 16:28:37 -0700 Message-ID: Subject: Re: [PATCH bpf-next v2] selftests/bpf: Fix issues in parse_num_list() To: Yuntao Wang Cc: Andrii Nakryiko , Alexei Starovoitov , bpf , Daniel Borkmann , john fastabend , Martin Lau , KP Singh , open list , "open list:KERNEL SELFTEST FRAMEWORK" , Networking , Shuah Khan , Song Liu , Yonghong Song Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 4, 2022 at 11:24 PM Yuntao Wang 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 > --- > 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 >