]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-rules: ignore whole command result if it is too long and does not contain newline
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 15 Jan 2025 14:43:37 +0000 (23:43 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Jan 2025 19:19:52 +0000 (04:19 +0900)
src/udev/udev-rules.c

index 0ba7f6beb8d060057b4b5e019d70a88e1f64abed..3ea1a2346b0ededf72e97f57ba5da076716ca66b 100644 (file)
@@ -2380,15 +2380,18 @@ static int udev_rule_apply_token_to_event(
                 }
 
                 if (truncated) {
-                        bool found = false;
+                        log_event_debug(event, token, "Result of \"%s\" is too long and truncated, ignoring the last line of the result.", buf);
 
                         /* Drop the last line. */
+                        bool found = false;
                         for (char *p = PTR_SUB1(buf + strlen(buf), buf); p; p = PTR_SUB1(p, buf))
                                 if (strchr(NEWLINE, *p)) {
                                         *p = '\0';
                                         found = true;
-                                } else if (found)
                                         break;
+                                }
+                        if (!found)
+                                buf[0] = '\0';
                 }
 
                 r = strv_split_newlines_full(&lines, result, EXTRACT_RETAIN_ESCAPE);