Patchwork [U-Boot,01/20] Tidy up error checking and fix bug in hash command

login
register
mail settings
Submitter Simon Glass
Date Dec. 26, 2012, 6:56 p.m.
Message ID <1356548233-5570-2-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/208192/
State Superseded, archived
Delegated to: Simon Glass
Headers show

Comments

Simon Glass - Dec. 26, 2012, 6:56 p.m.
There are two problems:

1. The argument count needs to be checked before argv is used
2. When verify is not enabled, we need to define a constant zero value

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/cmd_hash.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Simon Glass - Feb. 15, 2013, 11:48 p.m.
On Wed, Dec 26, 2012 at 10:56 AM, Simon Glass <sjg@chromium.org> wrote:
> There are two problems:
>
> 1. The argument count needs to be checked before argv is used
> 2. When verify is not enabled, we need to define a constant zero value
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to x86/master.

Patch

diff --git a/common/cmd_hash.c b/common/cmd_hash.c
index 689c608..eb6a338 100644
--- a/common/cmd_hash.c
+++ b/common/cmd_hash.c
@@ -32,11 +32,15 @@  static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #ifdef CONFIG_HASH_VERIFY
 	int verify = 0;
 
+	if (argc < 4)
+		return CMD_RET_USAGE;
 	if (!strcmp(argv[1], "-v")) {
 		verify = 1;
 		argc--;
 		argv++;
 	}
+#else
+	const int verify = 0;
 #endif
 	/* Move forward to 'algorithm' parameter */
 	argc--;