All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load
@ 2014-07-09 20:42 Pavel Machek
  2014-07-09 20:46 ` Pavel Machek
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Pavel Machek @ 2014-07-09 20:42 UTC (permalink / raw)
  To: u-boot


If filename is passed instead of address to ext2load or fatload,
u-boot silently accepts that, and uses 0 for load address and default
filename from environment. That is confusing, display help instead.
    
Signed-off-by: Pavel Machek <pavel@denx.de>

diff --git a/fs/fs.c b/fs/fs.c
index 79d432d..ea15c5f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -276,6 +276,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 	unsigned long pos;
 	int len_read;
 	unsigned long time;
+	char *ep;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
@@ -286,7 +287,9 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		return 1;
 
 	if (argc >= 4) {
-		addr = simple_strtoul(argv[3], NULL, 16);
+		addr = simple_strtoul(argv[3], &ep, 16);
+		if (ep == argv[3] || *ep != '\0')
+			return CMD_RET_USAGE;
 	} else {
 		addr_str = getenv("loadaddr");
 		if (addr_str != NULL)

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load
  2014-07-09 20:42 [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load Pavel Machek
@ 2014-07-09 20:46 ` Pavel Machek
  2014-07-09 21:07 ` Marek Vasut
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Pavel Machek @ 2014-07-09 20:46 UTC (permalink / raw)
  To: u-boot

Hi!

> If filename is passed instead of address to ext2load or fatload,
> u-boot silently accepts that, and uses 0 for load address and default
> filename from environment. That is confusing, display help instead.
>     
> Signed-off-by: Pavel Machek <pavel@denx.de>

Oops and actually I should warn... this patch is untested. I'm
currently fighting hard to get recent u-boot to run on socfpga.

								Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load
  2014-07-09 20:42 [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load Pavel Machek
  2014-07-09 20:46 ` Pavel Machek
@ 2014-07-09 21:07 ` Marek Vasut
  2014-07-09 22:57   ` Pavel Machek
  2014-07-09 23:08 ` Wolfgang Denk
  2014-07-22 19:22 ` [U-Boot] " Tom Rini
  3 siblings, 1 reply; 7+ messages in thread
From: Marek Vasut @ 2014-07-09 21:07 UTC (permalink / raw)
  To: u-boot

On Wednesday, July 09, 2014 at 10:42:57 PM, Pavel Machek wrote:
> If filename is passed instead of address to ext2load or fatload,
> u-boot silently accepts that, and uses 0 for load address and default
> filename from environment. That is confusing, display help instead.
> 
> Signed-off-by: Pavel Machek <pavel@denx.de>

The handling of simple_strtoul() in fs.c could use improvement like this in 
general. Do you mind expanding this patch ?

Best regards,
Marek Vasut

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

* [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load
  2014-07-09 21:07 ` Marek Vasut
@ 2014-07-09 22:57   ` Pavel Machek
  0 siblings, 0 replies; 7+ messages in thread
From: Pavel Machek @ 2014-07-09 22:57 UTC (permalink / raw)
  To: u-boot

On Wed 2014-07-09 23:07:56, Marek Vasut wrote:
> On Wednesday, July 09, 2014 at 10:42:57 PM, Pavel Machek wrote:
> > If filename is passed instead of address to ext2load or fatload,
> > u-boot silently accepts that, and uses 0 for load address and default
> > filename from environment. That is confusing, display help instead.
> > 
> > Signed-off-by: Pavel Machek <pavel@denx.de>
> 
> The handling of simple_strtoul() in fs.c could use improvement like this in 
> general. Do you mind expanding this patch ?

I'd prefer not to do that at this moment: I don't have working-enough
u-boot and hate to do changes without testing.

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load
  2014-07-09 20:42 [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load Pavel Machek
  2014-07-09 20:46 ` Pavel Machek
  2014-07-09 21:07 ` Marek Vasut
@ 2014-07-09 23:08 ` Wolfgang Denk
  2014-07-09 23:12   ` Pavel Machek
  2014-07-22 19:22 ` [U-Boot] " Tom Rini
  3 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Denk @ 2014-07-09 23:08 UTC (permalink / raw)
  To: u-boot

Dear Pavel Machek,

In message <20140709204257.GA28671@amd.pavel.ucw.cz> you wrote:
> 
> If filename is passed instead of address to ext2load or fatload,
> u-boot silently accepts that, and uses 0 for load address and default
> filename from environment. That is confusing, display help instead.
>     
> Signed-off-by: Pavel Machek <pavel@denx.de>
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index 79d432d..ea15c5f 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -276,6 +276,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
>  	unsigned long pos;
>  	int len_read;
>  	unsigned long time;
> +	char *ep;
>  
>  	if (argc < 2)
>  		return CMD_RET_USAGE;
> @@ -286,7 +287,9 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
>  		return 1;
>  
>  	if (argc >= 4) {
> -		addr = simple_strtoul(argv[3], NULL, 16);
> +		addr = simple_strtoul(argv[3], &ep, 16);
> +		if (ep == argv[3] || *ep != '\0')
> +			return CMD_RET_USAGE;

What happens in case of filenames that look like numbers, say "0"?
It may be silly to use such, but it should not be impossible to do so.

Viele Gr??e,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
One difference between a man and a machine is that a machine is quiet
when well oiled.

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

* [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load
  2014-07-09 23:08 ` Wolfgang Denk
@ 2014-07-09 23:12   ` Pavel Machek
  0 siblings, 0 replies; 7+ messages in thread
From: Pavel Machek @ 2014-07-09 23:12 UTC (permalink / raw)
  To: u-boot

On Thu 2014-07-10 01:08:28, Wolfgang Denk wrote:
> Dear Pavel Machek,
> 
> In message <20140709204257.GA28671@amd.pavel.ucw.cz> you wrote:
> > 
> > If filename is passed instead of address to ext2load or fatload,
> > u-boot silently accepts that, and uses 0 for load address and default
> > filename from environment. That is confusing, display help instead.
> >     
> > Signed-off-by: Pavel Machek <pavel@denx.de>
> > 
> > diff --git a/fs/fs.c b/fs/fs.c
> > index 79d432d..ea15c5f 100644
> > --- a/fs/fs.c
> > +++ b/fs/fs.c
> > @@ -276,6 +276,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
> >  	unsigned long pos;
> >  	int len_read;
> >  	unsigned long time;
> > +	char *ep;
> >  
> >  	if (argc < 2)
> >  		return CMD_RET_USAGE;
> > @@ -286,7 +287,9 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
> >  		return 1;
> >  
> >  	if (argc >= 4) {
> > -		addr = simple_strtoul(argv[3], NULL, 16);
> > +		addr = simple_strtoul(argv[3], &ep, 16);
> > +		if (ep == argv[3] || *ep != '\0')
> > +			return CMD_RET_USAGE;
> 
> What happens in case of filenames that look like numbers, say "0"?
> It may be silly to use such, but it should not be impossible to do
> so.

It should be ok.

This catches error when someone passes non-number as a load
address. As long as you pass load address, nothing changes.

IOW  

fatload mmc 0:1 0 filename
# always worked/keeps working
fatload mmc 0:1 filename
# before my patch, this would try to parse filename as number, fail,
# and use default load address adn default filename. Not what user
# wanted.
fatload mmc 0:1 0 0
# Load filename "0" at address 0. Worked before, will work now.

Hope this helps,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* [U-Boot] catch wrong load address passed to fatload / ext2load
  2014-07-09 20:42 [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load Pavel Machek
                   ` (2 preceding siblings ...)
  2014-07-09 23:08 ` Wolfgang Denk
@ 2014-07-22 19:22 ` Tom Rini
  3 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2014-07-22 19:22 UTC (permalink / raw)
  To: u-boot

On Wed, Jul 09, 2014 at 10:42:57PM +0200, Pavel Machek wrote:

> If filename is passed instead of address to ext2load or fatload,
> u-boot silently accepts that, and uses 0 for load address and default
> filename from environment. That is confusing, display help instead.
>     
> Signed-off-by: Pavel Machek <pavel@denx.de>

Applied to u-boot/master, thanks!

-- 
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/20140722/cdb455c9/attachment.pgp>

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

end of thread, other threads:[~2014-07-22 19:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-09 20:42 [U-Boot] [PATCH] catch wrong load address passed to fatload / ext2load Pavel Machek
2014-07-09 20:46 ` Pavel Machek
2014-07-09 21:07 ` Marek Vasut
2014-07-09 22:57   ` Pavel Machek
2014-07-09 23:08 ` Wolfgang Denk
2014-07-09 23:12   ` Pavel Machek
2014-07-22 19:22 ` [U-Boot] " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.