[PATCH 05/12] logger: check numeric priority and facility input values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 misc-utils/logger.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index fccba38..b7f9064 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);
-- 
1.9.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux