fix array over-run in efi.c
PATCH 1/1 fix array over-run in efi.c
From: Darren Jenkins <[email protected]>
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.
---
This patch was sent by Darren Jenkins on:
- 08 Mar 2006
arch/i386/kernel/efi.c renamed from arch/i386/kernel/efi.c.orig +1 -1
@@ -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
arch/i386/kernel/efi.c void __init efi_init(void) · line 362
Quoted 3 lines
arch/i386/kernel/efi.c renamed from arch/i386/kernel/efi.c.orig +1
-1-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
Quoted 6 lines · Jan Engelhardt
arch/i386/kernel/efi.c void __init efi_init(void) · line 362
Quoted 3 lines
arch/i386/kernel/efi.c renamed from arch/i386/kernel/efi.c.orig +1
-1-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.
Quoted 1 line
Jan Engelhardt
cu
Adrian
Signature · 4 lines
"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 SeedQuoted 8 lines · Jan Engelhardt
Review
Quoted 2 lines
(quoted diff) +1
-1- 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.
arch/i386/kernel/efi.c renamed from arch/i386/kernel/efi.c.orig +1 -1
@@ -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