udev: prepare memory for extra NUL termination for NULSTR
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Apr 2020 11:36:00 +0000 (13:36 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 30 May 2020 18:03:48 +0000 (20:03 +0200)
Fixes: #15162
(cherry picked from commit cd3c8a117ccf3505e49d34324473e2175ef0a9ce)

src/udev/udev-rules.c

index b990f68e933c19933290c2e08d402a8e7cf260c0..04e1c976fb759605d60b6819c1c97e81043fc166 100644 (file)
@@ -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();