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
This commit is contained in:
parent
fe756ed9ec
commit
ee7122c0ec
|
@ -159,9 +159,13 @@ int util_log_priority(const char *priority)
|
||||||
char *endptr;
|
char *endptr;
|
||||||
int prio;
|
int prio;
|
||||||
|
|
||||||
prio = strtol(priority, &endptr, 10);
|
prio = strtoul(priority, &endptr, 10);
|
||||||
if (endptr[0] == '\0' || isspace(endptr[0]))
|
if (endptr[0] == '\0' || isspace(endptr[0])) {
|
||||||
return prio;
|
if (prio >= 0 && prio <= 7)
|
||||||
|
return prio;
|
||||||
|
else
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
return log_level_from_string(priority);
|
return log_level_from_string(priority);
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,13 @@ _public_ struct udev *udev_new(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (streq(key, "udev_log")) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,8 +207,15 @@ _public_ struct udev *udev_new(void)
|
||||||
|
|
||||||
/* environment overrides config */
|
/* environment overrides config */
|
||||||
env = secure_getenv("UDEV_LOG");
|
env = secure_getenv("UDEV_LOG");
|
||||||
if (env != NULL)
|
if (env != NULL) {
|
||||||
udev_set_log_priority(udev, util_log_priority(env));
|
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;
|
return udev;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue