68 lines
2.5 KiB
Diff
68 lines
2.5 KiB
Diff
|
Based on ee7122c0ec6aa11f02e9e8d94254b353f12d2c14 Mon Sep 17 00:00:00 2001
|
||
|
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
||
|
Date: Sat, 1 Nov 2014 12:06:41 -0400
|
||
|
Subject: [PATCH] libudev: do not accept invalid log levels
|
||
|
|
||
|
Invalid log levels lead to a assert failure later on.
|
||
|
|
||
|
https://bugs.freedesktop.org/show_bug.cgi?id=85657
|
||
|
---
|
||
|
src/libudev/libudev-util.c | 10 +++++++---
|
||
|
src/libudev/libudev.c | 19 ++++++++++++++++---
|
||
|
2 files changed, 23 insertions(+), 6 deletions(-)
|
||
|
|
||
|
--- src/libudev/libudev-util.c
|
||
|
+++ src/libudev/libudev-util.c 2014-11-10 11:33:26.269519209 +0000
|
||
|
@@ -255,9 +255,13 @@ int util_log_priority(const char *priori
|
||
|
char *endptr;
|
||
|
int prio;
|
||
|
|
||
|
- prio = strtol(priority, &endptr, 10);
|
||
|
- if (endptr[0] == '\0' || isspace(endptr[0]))
|
||
|
- return prio;
|
||
|
+ prio = strtoul(priority, &endptr, 10);
|
||
|
+ if (endptr[0] == '\0' || isspace(endptr[0])) {
|
||
|
+ if (prio >= 0 && prio <= 7)
|
||
|
+ return prio;
|
||
|
+ else
|
||
|
+ return -ERANGE;
|
||
|
+ }
|
||
|
if (startswith(priority, "err"))
|
||
|
return LOG_ERR;
|
||
|
if (startswith(priority, "info"))
|
||
|
--- src/libudev/libudev.c
|
||
|
+++ src/libudev/libudev.c
|
||
|
@@ -193,7 +193,13 @@ _public_ struct udev *udev_new(void)
|
||
|
}
|
||
|
|
||
|
if (streq(key, "udev_log")) {
|
||
|
- udev_set_log_priority(udev, util_log_priority(val));
|
||
|
+ int prio;
|
||
|
+
|
||
|
+ prio = util_log_priority(val);
|
||
|
+ if (prio < 0)
|
||
|
+ udev_err(udev, "/etc/udev/udev.conf:%u: invalid logging level '%s', ignoring.\n", line_nr, val);
|
||
|
+ else
|
||
|
+ udev_set_log_priority(udev, prio);
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
@@ -201,8 +207,15 @@ _public_ struct udev *udev_new(void)
|
||
|
|
||
|
/* environment overrides config */
|
||
|
env = secure_getenv("UDEV_LOG");
|
||
|
- if (env != NULL)
|
||
|
- udev_set_log_priority(udev, util_log_priority(env));
|
||
|
+ if (env != NULL) {
|
||
|
+ int prio;
|
||
|
+
|
||
|
+ prio = util_log_priority(env);
|
||
|
+ if (prio < 0)
|
||
|
+ udev_err(udev, "$UDEV_LOG specifies invalid logging level '%s', ignoring.\n", env);
|
||
|
+ else
|
||
|
+ udev_set_log_priority(udev, prio);
|
||
|
+ }
|
||
|
|
||
|
return udev;
|
||
|
}
|