summaryrefslogtreecommitdiffstats
path: root/misc-utils/logger.c
diff options
context:
space:
mode:
authorSami Kerola2014-05-11 21:26:42 +0200
committerKarel Zak2014-05-12 13:07:09 +0200
commit4d7d1af6745f79cdf591bf45d74a8cd9f4a65a6c (patch)
tree570b725441ff57894efce891361a987b25f26531 /misc-utils/logger.c
parentlogger: fail when io vector number exceeds maximum (diff)
downloadkernel-qcow2-util-linux-4d7d1af6745f79cdf591bf45d74a8cd9f4a65a6c.tar.gz
kernel-qcow2-util-linux-4d7d1af6745f79cdf591bf45d74a8cd9f4a65a6c.tar.xz
kernel-qcow2-util-linux-4d7d1af6745f79cdf591bf45d74a8cd9f4a65a6c.zip
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 <kerolasa@iki.fi>
Diffstat (limited to 'misc-utils/logger.c')
-rw-r--r--misc-utils/logger.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index fccba3880..b7f90649c 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);