public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [2.6 patch] fix array over-run in efi.c
@ 2006-03-25 11:58 Adrian Bunk
  2006-03-25 18:41 ` Jan Engelhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Adrian Bunk @ 2006-03-25 11:58 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Darren Jenkins

From: Darren Jenkins <darrenrjenkins@gmail.com>

Coverity found an over-run @ line 364 of efi.c

This is due to the loop checking the size correctly, then adding a '\0'
after possibly hitting the end of the array.

The patch below just ensures the loop exits with one space left in the
array.

Compile tested.


Signed-off-by: Darren Jenkins <darrenrjenkins@gmail.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>

---

This patch was sent by Darren Jenkins on:
- 08 Mar 2006

--- linux-2.6.16-rc5/arch/i386/kernel/efi.c.orig	2006-03-08 12:31:14.000000000 +1100
+++ linux-2.6.16-rc5/arch/i386/kernel/efi.c	2006-03-08 12:37:59.000000000 +1100
@@ -359,7 +359,7 @@ void __init efi_init(void)
 	 */
 	c16 = (efi_char16_t *) boot_ioremap(efi.systab->fw_vendor, 2);
 	if (c16) {
-		for (i = 0; i < sizeof(vendor) && *c16; ++i)
+		for (i = 0; i < (sizeof(vendor) - 1) && *c16; ++i)
 			vendor[i] = *c16++;
 		vendor[i] = '\0';
 	} else




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

* Re: [2.6 patch] fix array over-run in efi.c
  2006-03-25 11:58 [2.6 patch] fix array over-run in efi.c Adrian Bunk
@ 2006-03-25 18:41 ` Jan Engelhardt
  2006-03-25 21:15   ` Adrian Bunk
  2006-03-26  2:18   ` Darren Jenkins\
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Engelhardt @ 2006-03-25 18:41 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: Andrew Morton, linux-kernel, Darren Jenkins


>-		for (i = 0; i < sizeof(vendor) && *c16; ++i)
>+		for (i = 0; i < (sizeof(vendor) - 1) && *c16; ++i)

                for (i = 0; i <  sizeof(vendor) - 1  && *c16; ++i)
Should suffice.


Jan Engelhardt
-- 

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

* Re: [2.6 patch] fix array over-run in efi.c
  2006-03-25 18:41 ` Jan Engelhardt
@ 2006-03-25 21:15   ` Adrian Bunk
  2006-03-26  2:18   ` Darren Jenkins\
  1 sibling, 0 replies; 4+ messages in thread
From: Adrian Bunk @ 2006-03-25 21:15 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Andrew Morton, linux-kernel, Darren Jenkins

On Sat, Mar 25, 2006 at 07:41:56PM +0100, Jan Engelhardt wrote:
> 
> >-		for (i = 0; i < sizeof(vendor) && *c16; ++i)
> >+		for (i = 0; i < (sizeof(vendor) - 1) && *c16; ++i)
> 
>                 for (i = 0; i <  sizeof(vendor) - 1  && *c16; ++i)
> Should suffice.

That's irrelevant.
The important question is readability.

> Jan Engelhardt

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


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

* Re: [2.6 patch] fix array over-run in efi.c
  2006-03-25 18:41 ` Jan Engelhardt
  2006-03-25 21:15   ` Adrian Bunk
@ 2006-03-26  2:18   ` Darren Jenkins\
  1 sibling, 0 replies; 4+ messages in thread
From: Darren Jenkins\ @ 2006-03-26  2:18 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Adrian Bunk, Andrew Morton, linux-kernel

On Sat, 2006-03-25 at 19:41 +0100, Jan Engelhardt wrote:
> >-		for (i = 0; i < sizeof(vendor) && *c16; ++i)
> >+		for (i = 0; i < (sizeof(vendor) - 1) && *c16; ++i)
> 
>                 for (i = 0; i <  sizeof(vendor) - 1  && *c16; ++i)
> Should suffice.
> 
> 
> Jan Engelhardt


OK since it is preferred without the brackets, here it is again.



Coverity found an over-run @ line 364 of efi.c

This is due to the loop checking the size correctly, then adding a '\0'
after possibly hitting the end of the array.

The patch below just ensures the loop exits with one space left in the
array.

Compile tested.

Signed-off-by: Darren Jenkins <darrenrjenkins@gmail.com>

--- linux-2.6.16-git8/arch/i386/kernel/efi.c.orig	2006-03-26 12:06:47.000000000 +1000
+++ linux-2.6.16-git8/arch/i386/kernel/efi.c	2006-03-26 12:08:34.000000000 +1000
@@ -361,7 +361,7 @@ void __init efi_init(void)
 	 */
 	c16 = (efi_char16_t *) boot_ioremap(efi.systab->fw_vendor, 2);
 	if (c16) {
-		for (i = 0; i < sizeof(vendor) && *c16; ++i)
+		for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i)
 			vendor[i] = *c16++;
 		vendor[i] = '\0';
 	} else





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

end of thread, other threads:[~2006-03-26  2:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-25 11:58 [2.6 patch] fix array over-run in efi.c Adrian Bunk
2006-03-25 18:41 ` Jan Engelhardt
2006-03-25 21:15   ` Adrian Bunk
2006-03-26  2:18   ` Darren Jenkins\

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