[U-Boot] [PATCH v3 01/22] Tidy up error checking and fix bug in hash command

Simon Glass sjg at chromium.org
Mon Feb 25 04:33:11 CET 2013


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 at chromium.org>
---
Changes in v3: None
Changes in v2: None

 common/cmd_hash.c | 4 ++++
 1 file changed, 4 insertions(+)

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--;
-- 
1.8.1.3



More information about the U-Boot mailing list