]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: check numeric priority and facility input values
authorSami Kerola <kerolasa@iki.fi>
Sun, 11 May 2014 19:26:42 +0000 (20:26 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 12 May 2014 11:07:09 +0000 (13:07 +0200)
Earlier use of unknown facility or priority number was accepted, and
resulted in unexpected result.  For example when looking journalctl
--priority=7.8 was converted to priotity 0 and facility 1.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/logger.c

index fccba3880ce508312442c64129fed96d347a6117..b7f90649c742c7dccadee510b68e4fdd782c2540 100644 (file)
@@ -99,9 +99,20 @@ static int decode(char *name, CODE *codetab)
 {
        register CODE *c;
 
-       if (isdigit(*name))
-               return (atoi(name));
-
+       if (name == NULL || *name == '\0')
+               return -1;
+       if (isdigit(*name)) {
+               int num;
+               char *end = NULL;
+
+               num = strtol(name, &end, 10);
+               if (errno || name == end || (end && *end))
+                       return -1;
+               for (c = codetab; c->c_name; c++)
+                       if (num == c->c_val)
+                               return num;
+               return -1;
+       }
        for (c = codetab; c->c_name; c++)
                if (!strcasecmp(name, c->c_name))
                        return (c->c_val);