]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
log: check argument of 'log level' command
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Sun, 31 May 2020 13:44:51 +0000 (13:44 +0000)
committerSimon Glass <sjg@chromium.org>
Fri, 12 Jun 2020 02:52:11 +0000 (20:52 -0600)
Check that the argument provided to the 'log level' command is in the range
between zero and CONFIG_LOG_MAX_LEVEL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/log.c

index 664f7bd7ac4ed7a0e9eadc88ef53fc7552112b70..78352b2cb91c8a802a792264a0dcc598d009c49f 100644 (file)
--- a/cmd/log.c
+++ b/cmd/log.c
@@ -14,10 +14,18 @@ static char log_fmt_chars[LOGF_COUNT] = "clFLfm";
 static int do_log_level(struct cmd_tbl *cmdtp, int flag, int argc,
                        char *const argv[])
 {
-       if (argc > 1)
-               gd->default_log_level = simple_strtol(argv[1], NULL, 10);
-       else
+       if (argc > 1) {
+               long log_level = simple_strtol(argv[1], NULL, 10);
+
+               if (log_level < 0 || log_level > _LOG_MAX_LEVEL) {
+                       printf("Only log levels <= %d are supported\n",
+                              _LOG_MAX_LEVEL);
+                       return CMD_RET_FAILURE;
+               }
+               gd->default_log_level = log_level;
+       } else {
                printf("Default log level: %d\n", gd->default_log_level);
+       }
 
        return 0;
 }