diff mbox

[U-Boot] vfat: Fix mkcksum argument sizes

Message ID 1357911348-28403-1-git-send-email-marex@denx.de
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Marek Vasut Jan. 11, 2013, 1:35 p.m. UTC
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.

Reported-by: Aaron Williams <Aaron.Williams@cavium.com>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <tom.rini@gmail.com>
Cc: Aaron Williams <Aaron.Williams@cavium.com>
---
 fs/fat/fat.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Michal Simek Jan. 28, 2013, 3:12 p.m. UTC | #1
2013/1/11 Marek Vasut <marex@denx.de>:
> 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.
>
> Reported-by: Aaron Williams <Aaron.Williams@cavium.com>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Tom Rini <tom.rini@gmail.com>
> Cc: Aaron Williams <Aaron.Williams@cavium.com>
> ---
>  fs/fat/fat.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Tested-by: Michal Simek <michal.simek@xilinx.com>

Thanks,
Michal
Joe Hershberger Jan. 31, 2013, 3:34 p.m. UTC | #2
On Fri, Jan 11, 2013 at 7:35 AM, Marek Vasut <marex@denx.de> wrote:
> 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.
>
> Reported-by: Aaron Williams <Aaron.Williams@cavium.com>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Tom Rini <tom.rini@gmail.com>
> Cc: Aaron Williams <Aaron.Williams@cavium.com>
> ---
>  fs/fat/fat.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index 393c378..25d3318 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -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;


Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Tom Rini Jan. 31, 2013, 7:44 p.m. UTC | #3
On Fri, Jan 11, 2013 at 03:35:48AM -0000, Marek Vasut wrote:

> 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.
> 
> Reported-by: Aaron Williams <Aaron.Williams@cavium.com>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Tom Rini <tom.rini@gmail.com>
> Cc: Aaron Williams <Aaron.Williams@cavium.com>
> Tested-by: Michal Simek <michal.simek@xilinx.com>
> Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

Applied to u-boot/master, thanks!
Marek Vasut Jan. 31, 2013, 8:53 p.m. UTC | #4
Dear Tom Rini,

> On Fri, Jan 11, 2013 at 03:35:48AM -0000, Marek Vasut wrote:
> > 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.
> > 
> > Reported-by: Aaron Williams <Aaron.Williams@cavium.com>
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Tom Rini <tom.rini@gmail.com>
> > Cc: Aaron Williams <Aaron.Williams@cavium.com>
> > Tested-by: Michal Simek <michal.simek@xilinx.com>
> > Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
> 
> 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
diff mbox

Patch

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 393c378..25d3318 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -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;