From: Sami Kerola Date: Sun, 11 May 2014 19:26:42 +0000 (+0100) Subject: logger: check numeric priority and facility input values X-Git-Tag: v2.25-rc1~186 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d7d1af6745f79cdf591bf45d74a8cd9f4a65a6c;p=thirdparty%2Futil-linux.git logger: check numeric priority and facility input values 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 --- diff --git a/misc-utils/logger.c b/misc-utils/logger.c index fccba3880c..b7f90649c7 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -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);