All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] cmd_mem: cleanups, catch bad usage
Date: Mon, 6 Apr 2015 15:44:34 +0200	[thread overview]
Message-ID: <20150406134434.GA10205@amd> (raw)
In-Reply-To: <20150401115041.GA5921@amd>

On Wed 2015-04-01 13:50:41, Pavel Machek wrote:
> Currently, memtest will silently accept bad data. Perform error
> checking on user intput.
> 
> Signed-off-by: Pavel Machek <pavel@denx.de>

Ping? Tom, noone replys here, can you take the patch?

> diff --git a/common/cmd_mem.c b/common/cmd_mem.c
> index bfca59e..e6623b0 100644
> --- a/common/cmd_mem.c
> +++ b/common/cmd_mem.c
> @@ -994,10 +994,10 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
>  {
>  	ulong start, end;
>  	vu_long *buf, *dummy;
> -	int iteration_limit;
> +	int iteration_limit = 0;
>  	int ret;
>  	ulong errs = 0;	/* number of errors, or -1 if interrupted */
> -	ulong pattern;
> +	ulong pattern = 0;
>  	int iteration;
>  #if defined(CONFIG_SYS_ALT_MEMTEST)
>  	const int alt_test = 1;
> @@ -1005,25 +1005,29 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
>  	const int alt_test = 0;
>  #endif
>  
> +	start = CONFIG_SYS_MEMTEST_START;
> +	end = CONFIG_SYS_MEMTEST_END;
> +
>  	if (argc > 1)
> -		start = simple_strtoul(argv[1], NULL, 16);
> -	else
> -		start = CONFIG_SYS_MEMTEST_START;
> +		if (strict_strtoul(argv[1], 16, &start) < 0)
> +			return CMD_RET_USAGE;
>  
>  	if (argc > 2)
> -		end = simple_strtoul(argv[2], NULL, 16);
> -	else
> -		end = CONFIG_SYS_MEMTEST_END;
> +		if (strict_strtoul(argv[2], 16, &end) < 0)
> +			return CMD_RET_USAGE;
>  
>  	if (argc > 3)
> -		pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
> -	else
> -		pattern = 0;
> +		if (strict_strtoul(argv[3], 16, &pattern) < 0)
> +			return CMD_RET_USAGE;
>  
>  	if (argc > 4)
> -		iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
> -	else
> -		iteration_limit = 0;
> +		if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
> +			return CMD_RET_USAGE;
> +
> +	if (end < start) {
> +		printf("Refusing to do empty test\n");
> +		return -1;
> +	}
>  
>  	printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
>  	debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
> @@ -1074,7 +1078,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
>  		ret = errs != 0;
>  	}
>  
> -	return ret;	/* not reached */
> +	return ret;
>  }
>  #endif	/* CONFIG_CMD_MEMTEST */
>  
> 

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

  reply	other threads:[~2015-04-06 13:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-01 11:50 [U-Boot] cmd_mem: cleanups, catch bad usage Pavel Machek
2015-04-06 13:44 ` Pavel Machek [this message]
2015-04-07 17:58 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150406134434.GA10205@amd \
    --to=pavel@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.