Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1743314

Re: [PATCH 1/2] RAS/CEC: Use the right length for "cec_disable"

From Thomas Gleixner <tglx@linutronix.de>
Newsgroups linux.kernel
Subject Re: [PATCH 1/2] RAS/CEC: Use the right length for "cec_disable"
Date 2017-10-02 22:50 +0200
Message-ID <uwfPj-ur-275@gated-at.bofh.it> (permalink)
References <uw5cZ-5yk-5@gated-at.bofh.it> <uw5d0-5yk-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, 2 Oct 2017, Borislav Petkov wrote:
> From: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
> 
> parse_cec_param() compares a string with "cec_disable" using only 7
> characters of the 11-character-long string. Fix the length.
> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
> Fixes: 011d82611172 ("RAS: Add a Corrected Errors Collector")
> Link: http://lkml.kernel.org/r/20170903075440.30250-1-nicolas.iooss_linux@m4x.org
> Signed-off-by: Borislav Petkov <bp@suse.de>
> ---
>  drivers/ras/cec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
> index d0e5d6ee882c..586c296d1538 100644
> --- a/drivers/ras/cec.c
> +++ b/drivers/ras/cec.c
> @@ -523,7 +523,7 @@ int __init parse_cec_param(char *str)
>  	if (*str == '=')
>  		str++;
>  
> -	if (!strncmp(str, "cec_disable", 7))
> +	if (!strncmp(str, "cec_disable", 11))

This kind of issue happens over and over. So if you really want to use
strncmp() then this should be:

#define	CEC_DISABLE	"cec_disable"

	if (!strncmp(str, CEC_DISABLE, strlen(CEC_DISABLE))

or we get a proper helper for that. Though in case of comparing some string
against a constant string strncmp() has no real advantage over strcmp() as
the comparison is guaranteed to be bound by the string constant.

Thanks,

	tglx

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/2] RAS: two fixlets Borislav Petkov <bp@alien8.de> - 2017-10-02 11:30 +0200
  [PATCH 1/2] RAS/CEC: Use the right length for "cec_disable" Borislav Petkov <bp@alien8.de> - 2017-10-02 11:30 +0200
    Re: [PATCH 1/2] RAS/CEC: Use the right length for "cec_disable" Thomas Gleixner <tglx@linutronix.de> - 2017-10-02 22:50 +0200
  [PATCH 2/2] x86/mce: Hide mca_cfg Borislav Petkov <bp@alien8.de> - 2017-10-02 11:30 +0200

csiph-web