Check the result of hextoul() when parsing the first argument to booti,
and add specific handling for "-h" to print usage rather than causing a
null pointer exception.

Fixes: 5db28905c952 ("cmd: Split 'bootz' and 'booti' out from 'bootm'")
Signed-off-by: Caleb Connolly <[email protected]>
---
 cmd/booti.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/cmd/booti.c b/cmd/booti.c
index 62b19e834366..c4029a84e7a7 100644
--- a/cmd/booti.c
+++ b/cmd/booti.c
@@ -31,8 +31,9 @@ static int booti_start(struct bootm_info *bmi)
        ulong dest_end;
        unsigned long comp_len;
        unsigned long decomp_len;
        int ctype;
+       char *endp;
 
        ret = bootm_run_states(bmi, BOOTM_STATE_START);
 
        /* Setup Linux kernel Image entry point */
@@ -40,9 +41,14 @@ static int booti_start(struct bootm_info *bmi)
                ld = image_load_addr;
                debug("*  kernel: default image load address = 0x%08lx\n",
                                image_load_addr);
        } else {
-               ld = hextoul(bmi->addr_img, NULL);
+               ld = hextoul(bmi->addr_img, &endp);
+               if (*endp != '\0') {
+                       printf("## Invalid kernel image address: %s\n",
+                              bmi->addr_img);
+                       return CMD_RET_USAGE;
+               }
                debug("*  kernel: cmdline image address = 0x%08lx\n", ld);
        }
 
        temp = map_sysmem(ld, 0);
@@ -108,8 +114,11 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
 
        /* Consume 'booti' */
        argc--; argv++;
 
+       if (argc && strcmp(argv[0], "-h") == 0)
+               return CMD_RET_USAGE;
+
        bootm_init(&bmi);
        if (argc)
                bmi.addr_img = argv[0];
        if (argc > 1)
-- 
2.45.0

Reply via email to