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] [day] [month] [year] [list]
Message-ID: <df75fa45950ab7bb67da52fe4b711209790e52ef.camel@perches.com>
Date:   Thu, 01 Aug 2019 20:13:06 -0700
From:   Joe Perches <joe@...ches.com>
To:     Chuhong Yuan <hslester96@...il.com>
Cc:     Petr Mladek <pmladek@...e.com>,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 06/10] printk: Replace strncmp with str_has_prefix

On Fri, 2019-08-02 at 09:47 +0800, Chuhong Yuan wrote:
> strncmp(str, const, len) is error-prone because len
> is easy to have typo.
> The example is the hard-coded len has counting error
> or sizeof(const) forgets - 1.
> So we prefer using newly introduced str_has_prefix
> to substitute such strncmp.
[]
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
[]
> @@ -118,18 +118,20 @@ static unsigned int __read_mostly devkmsg_log = DEVKMSG_LOG_MASK_DEFAULT;
>  
>  static int __control_devkmsg(char *str)
>  {
> +	size_t len;
> +
>  	if (!str)
>  		return -EINVAL;
>  
> -	if (!strncmp(str, "on", 2)) {
> +	if ((len = str_has_prefix(str, "on"))) {
>  		devkmsg_log = DEVKMSG_LOG_MASK_ON;
> -		return 2;
> -	} else if (!strncmp(str, "off", 3)) {
> +		return len;
> +	} else if ((len = str_has_prefix(str, "off"))) {
>  		devkmsg_log = DEVKMSG_LOG_MASK_OFF;
> -		return 3;
> -	} else if (!strncmp(str, "ratelimit", 9)) {
> +		return len;
> +	} else if ((len = str_has_prefix(str, "ratelimit"))) {
>  		devkmsg_log = DEVKMSG_LOG_MASK_DEFAULT;
> -		return 9;
> +		return len;
>  	}
>  	return -EINVAL;
>  }

All of the else uses above could also be removed.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ