lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANhBUQ2RD065Dn8eGkbzSQxfie5XrR_kgaFQ1QgOS4cKNhAfPA@mail.gmail.com>
Date:   Thu, 1 Aug 2019 23:23:33 +0800
From:   Chuhong Yuan <hslester96@...il.com>
To:     Joe Perches <joe@...ches.com>
Cc:     Petr Mladek <pmladek@...e.com>,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 08/12] printk: Replace strncmp with str_has_prefix

Joe Perches <joe@...ches.com> 于2019年7月30日周二 上午8:16写道:
>
> On Mon, 2019-07-29 at 23:15 +0800, Chuhong Yuan wrote:
> > strncmp(str, const, len) is error-prone.
> > We had better use newly introduced
> > str_has_prefix() instead of it.
> []
> > diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c
> []
> > @@ -11,10 +11,10 @@
> >
> >  int _braille_console_setup(char **str, char **brl_options)
> >  {
> > -     if (!strncmp(*str, "brl,", 4)) {
> > +     if (str_has_prefix(*str, "brl,")) {
> >               *brl_options = "";
> >               *str += 4;
> > -     } else if (!strncmp(*str, "brl=", 4)) {
> > +     } else if (str_has_prefix(*str, "brl=")) {
> >               *brl_options = *str + 4;
>
> Better to get rid of the += 4 uses too by storing the result
> of str_has_prefix and using that as the addend.
>
> Perhaps
>         size_t len;
>
>         if ((len = str_has_prefix(*str, "brl,"))) {
>                 *brl_options = "";
>                 *str += len;
>         } else if ((len = str_has_prefix(*str, "brl="))) {
>                 etc...
>

I find that checkpatch.pl forbids assignment in if condition.
So this seems to be infeasible...

> >               *str = strchr(*brl_options, ',');
> >               if (!*str) {
> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> []
> > @@ -121,13 +121,13 @@ static int __control_devkmsg(char *str)
> >       if (!str)
> >               return -EINVAL;
> >
> > -     if (!strncmp(str, "on", 2)) {
> > +     if (str_has_prefix(str, "on")) {
> >               devkmsg_log = DEVKMSG_LOG_MASK_ON;
> >               return 2;
> > -     } else if (!strncmp(str, "off", 3)) {
> > +     } else if (str_has_prefix(str, "off")) {
> >               devkmsg_log = DEVKMSG_LOG_MASK_OFF;
> >               return 3;
> > -     } else if (!strncmp(str, "ratelimit", 9)) {
> > +     } else if (str_has_prefix(str, "ratelimit")) {
> >               devkmsg_log = DEVKMSG_LOG_MASK_DEFAULT;
> >               return 9;
> >       }
>
> here too.
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ