public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arch: x86: platform: intel-mid: sfi.c:  Cleaning up missing null-terminate in conjunction with strncpy
@ 2014-07-26 22:26 Rickard Strandqvist
  2014-08-11 16:57 ` David Cohen
  0 siblings, 1 reply; 3+ messages in thread
From: Rickard Strandqvist @ 2014-07-26 22:26 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar
  Cc: Rickard Strandqvist, H. Peter Anvin, x86, David Cohen,
	Kuppuswamy Sathyanarayanan, Fei Yang, Fengguang Wu, linux-kernel

If you are going to use memset before strncpy you must copy sizeof -1

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 arch/x86/platform/intel-mid/sfi.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/platform/intel-mid/sfi.c b/arch/x86/platform/intel-mid/sfi.c
index 994c40b..97e79c9 100644
--- a/arch/x86/platform/intel-mid/sfi.c
+++ b/arch/x86/platform/intel-mid/sfi.c
@@ -359,7 +359,7 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
 	void *pdata = NULL;
 
 	memset(&spi_info, 0, sizeof(spi_info));
-	strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
+	strncpy(spi_info.modalias, pentry->name, sizeof(spi_info.modalias) - 1);
 	spi_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
 	spi_info.bus_num = pentry->host_num;
 	spi_info.chip_select = pentry->addr;
@@ -389,7 +389,7 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
 	void *pdata = NULL;
 
 	memset(&i2c_info, 0, sizeof(i2c_info));
-	strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
+	strncpy(i2c_info.type, pentry->name, sizeof(i2c_info.type) - 1);
 	i2c_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
 	i2c_info.addr = pentry->addr;
 	pr_debug("I2C bus = %d, name = %16.16s, irq = 0x%2x, addr = 0x%x\n",
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] arch: x86: platform: intel-mid: sfi.c:  Cleaning up missing null-terminate in conjunction with strncpy
  2014-07-26 22:26 [PATCH] arch: x86: platform: intel-mid: sfi.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
@ 2014-08-11 16:57 ` David Cohen
  2014-08-11 17:51   ` David Cohen
  0 siblings, 1 reply; 3+ messages in thread
From: David Cohen @ 2014-08-11 16:57 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Kuppuswamy Sathyanarayanan, Fei Yang, Fengguang Wu, linux-kernel

Hi Rickard,

Sorry for the late reply. Just came back from vacation :)

On Sun, Jul 27, 2014 at 12:26:58AM +0200, Rickard Strandqvist wrote:
> If you are going to use memset before strncpy you must copy sizeof -1

I agree it is way safer to not reply on firmware to have the null
terminator in place. But can you provide a better patch description? :)
It would be better if it is not a line addressed directly to the author.
Please refer the null terminator concern too.

Br, David

> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  arch/x86/platform/intel-mid/sfi.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/platform/intel-mid/sfi.c b/arch/x86/platform/intel-mid/sfi.c
> index 994c40b..97e79c9 100644
> --- a/arch/x86/platform/intel-mid/sfi.c
> +++ b/arch/x86/platform/intel-mid/sfi.c
> @@ -359,7 +359,7 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
>  	void *pdata = NULL;
>  
>  	memset(&spi_info, 0, sizeof(spi_info));
> -	strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
> +	strncpy(spi_info.modalias, pentry->name, sizeof(spi_info.modalias) - 1);
>  	spi_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
>  	spi_info.bus_num = pentry->host_num;
>  	spi_info.chip_select = pentry->addr;
> @@ -389,7 +389,7 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
>  	void *pdata = NULL;
>  
>  	memset(&i2c_info, 0, sizeof(i2c_info));
> -	strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
> +	strncpy(i2c_info.type, pentry->name, sizeof(i2c_info.type) - 1);
>  	i2c_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
>  	i2c_info.addr = pentry->addr;
>  	pr_debug("I2C bus = %d, name = %16.16s, irq = 0x%2x, addr = 0x%x\n",
> -- 
> 1.7.10.4
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] arch: x86: platform: intel-mid: sfi.c:  Cleaning up missing null-terminate in conjunction with strncpy
  2014-08-11 16:57 ` David Cohen
@ 2014-08-11 17:51   ` David Cohen
  0 siblings, 0 replies; 3+ messages in thread
From: David Cohen @ 2014-08-11 17:51 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86,
	Kuppuswamy Sathyanarayanan, Fei Yang, Fengguang Wu, linux-kernel

On Mon, Aug 11, 2014 at 09:57:39AM -0700, David Cohen wrote:
> Hi Rickard,
> 
> Sorry for the late reply. Just came back from vacation :)
> 
> On Sun, Jul 27, 2014 at 12:26:58AM +0200, Rickard Strandqvist wrote:
> > If you are going to use memset before strncpy you must copy sizeof -1
> 
> I agree it is way safer to not reply on firmware to have the null
> terminator in place. But can you provide a better patch description? :)
> It would be better if it is not a line addressed directly to the author.
> Please refer the null terminator concern too.

Guess my brain is not fully back from vacation after all :)
The patch subject mentions the null terminator.

Patch looks fine.

> 
> Br, David
> 
> > 
> > Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>

Acked-by: David Cohen <david.a.cohen@linux.intel.com>

> > ---
> >  arch/x86/platform/intel-mid/sfi.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/platform/intel-mid/sfi.c b/arch/x86/platform/intel-mid/sfi.c
> > index 994c40b..97e79c9 100644
> > --- a/arch/x86/platform/intel-mid/sfi.c
> > +++ b/arch/x86/platform/intel-mid/sfi.c
> > @@ -359,7 +359,7 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
> >  	void *pdata = NULL;
> >  
> >  	memset(&spi_info, 0, sizeof(spi_info));
> > -	strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
> > +	strncpy(spi_info.modalias, pentry->name, sizeof(spi_info.modalias) - 1);
> >  	spi_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
> >  	spi_info.bus_num = pentry->host_num;
> >  	spi_info.chip_select = pentry->addr;
> > @@ -389,7 +389,7 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
> >  	void *pdata = NULL;
> >  
> >  	memset(&i2c_info, 0, sizeof(i2c_info));
> > -	strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
> > +	strncpy(i2c_info.type, pentry->name, sizeof(i2c_info.type) - 1);
> >  	i2c_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
> >  	i2c_info.addr = pentry->addr;
> >  	pr_debug("I2C bus = %d, name = %16.16s, irq = 0x%2x, addr = 0x%x\n",
> > -- 
> > 1.7.10.4
> > 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-11 17:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-26 22:26 [PATCH] arch: x86: platform: intel-mid: sfi.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
2014-08-11 16:57 ` David Cohen
2014-08-11 17:51   ` David Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox