Skip to contentSkip to conversation

vfat: Fix mkcksum argument sizes

PATCH In review Marek Vasut 4 participants 5 messages Jan 11, 2013 – Jan 31, 2013 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfat: Fix mkcksum argument sizes

In case a function argument is known/fixed size array in C, the argument is still decoyed as pointer instead ( T f(U n[k]) ~= T fn(U *n) ) and therefore calling sizeof on the function argument will result in the size of the pointer, not the size of the array.

The VFAT code contains such a bug, this patch fixes it.

---
 fs/fat/fat.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/fat/fat.c +2 -2
index 393c378..25d3318 100644
@@ -569,9 +569,9 @@ static __u8 mkcksum(const char name[8], const char ext[3])
 
 	__u8 ret = 0;
 
-	for (i = 0; i < sizeof(name); i++)
+	for (i = 0; i < 8; i++)
 		ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + name[i];
-	for (i = 0; i < sizeof(ext); i++)
+	for (i = 0; i < 3; i++)
 		ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + ext[i];
 
 	return ret;
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 vfat: Fix mkcksum argument sizes

2013/1/11 Marek Vasut <[email protected]>:

Quoted 7 lines

In case a function argument is known/fixed size array in C, the argument is still decoyed as pointer instead ( T f(U n[k]) ~= T fn(U *n) ) and therefore calling sizeof on the function argument will result in the size of the pointer, not the size of the array.

The VFAT code contains such a bug, this patch fixes it.

Quoted 7 lines
---
 fs/fat/fat.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Thanks,
Michal

Signature · 5 lines
Michal Simek, Ing. (M.Eng)
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform
#2 lore raw

PATCH 1/1 vfat: Fix mkcksum argument sizes

In reply to Marek Vasut
Quoted 21 lines · Marek Vasut

In case a function argument is known/fixed size array in C, the argument is still decoyed as pointer instead ( T f(U n[k]) ~= T fn(U *n) ) and therefore calling sizeof on the function argument will result in the size of the pointer, not the size of the array.

The VFAT code contains such a bug, this patch fixes it.

---
 fs/fat/fat.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/fat/fat.c +0 -0
index 393c378..25d3318 100644
@@ -569,9 +569,9 @@ static __u8 mkcksum(const char name[8], const char ext[3])
 

fs/fat/fat.c static __u8 mkcksum(const char name[8], const char ext[3]) · line 577

Quoted 10 lines
fs/fat/fat.c +2 -2
        __u8 ret = 0;
 
-       for (i = 0; i < sizeof(name); i++)
+       for (i = 0; i < 8; i++)
                ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + name[i];
-       for (i = 0; i < sizeof(ext); i++)
+       for (i = 0; i < 3; i++)
                ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + ext[i];
 
        return ret;
#3 lore raw
In reply to Marek Vasut
Quoted 5 lines · Marek Vasut

In case a function argument is known/fixed size array in C, the argument is still decoyed as pointer instead ( T f(U n[k]) ~= T fn(U *n) ) and therefore calling sizeof on the function argument will result in the size of the pointer, not the size of the array.

Quoted 8 lines

The VFAT code contains such a bug, this patch fixes it.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130131/d0241b6c/attachment.pgp>
#4 lore raw

Dear Tom Rini,

Quoted 8 lines · Marek Vasut
Quoted 7 lines

In case a function argument is known/fixed size array in C, the argument is still decoyed as pointer instead ( T f(U n[k]) ~= T fn(U *n) ) and therefore calling sizeof on the function argument will result in the size of the pointer, not the size of the array.

The VFAT code contains such a bug, this patch fixes it.

Quoted 8 lines
Quoted 6 lines

Applied to u-boot/master, thanks!

Can we have a bugfix release 2013.02 or something ? This is a grave bug.

Best regards,
Marek Vasut