From cd3c8a117ccf3505e49d34324473e2175ef0a9ce Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 23 Apr 2020 13:36:00 +0200 Subject: [PATCH 1/2] udev: prepare memory for extra NUL termination for NULSTR Fixes: #15162 --- src/udev/udev-rules.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 6030ffb1f0..3bf3ee56f3 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1092,7 +1092,9 @@ static int rule_add_line(UdevRules *rules, const char *line_str, unsigned line_n if (isempty(line_str)) return 0; - line = strdup(line_str); + /* We use memdup_suffix0() here, since we want to add a second NUL byte to the end, since possibly + * some parsers might turn this into a "nulstr", which requires an extra NUL at the end. */ + line = memdup_suffix0(line_str, strlen(line_str) + 1); if (!line) return log_oom(); From 9663ed378e2fd7ba96bf9e87ca8452161e79801c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 23 Apr 2020 13:36:36 +0200 Subject: [PATCH 2/2] udev: use STR_IN_SET() wher eit makes sense --- src/udev/udev-rules.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 3bf3ee56f3..4c955b0c07 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1330,11 +1330,7 @@ static bool token_match_string(UdevRuleToken *token, const char *str) { match = isempty(str); break; case MATCH_TYPE_SUBSYSTEM: - NULSTR_FOREACH(i, "subsystem\0class\0bus\0") - if (streq(i, str)) { - match = true; - break; - } + match = STR_IN_SET(str, "subsystem", "class", "bus"); break; case MATCH_TYPE_PLAIN_WITH_EMPTY: if (isempty(str)) {