]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: use strv_split_newlines() to parse result of spawned command
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 21 Jan 2021 05:14:11 +0000 (14:14 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 1 Feb 2021 14:37:27 +0000 (23:37 +0900)
src/udev/udev-rules.c

index e72013ea56f945e13ed092708c1b45caaa69ee28..a87c5d119e61015948e779c33a19ef2a222d85f5 100644 (file)
@@ -1730,7 +1730,8 @@ static int udev_rule_apply_token_to_event(
                 return token->op == OP_MATCH;
         }
         case TK_M_IMPORT_PROGRAM: {
-                char result[UDEV_LINE_SIZE], *line, *pos;
+                _cleanup_strv_free_ char **lines = NULL;
+                char result[UDEV_LINE_SIZE], **line;
 
                 (void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
                 log_rule_debug(dev, rules, "Importing properties from results of '%s'", buf);
@@ -1744,18 +1745,18 @@ static int udev_rule_apply_token_to_event(
                         return token->op == OP_NOMATCH;
                 }
 
-                for (line = result; !isempty(line); line = pos) {
-                        char *key, *value;
+                lines = strv_split_newlines(result);
+                if (!lines)
+                        return log_oom();
 
-                        pos = strchr(line, '\n');
-                        if (pos)
-                                *pos++ = '\0';
+                STRV_FOREACH(line, lines) {
+                        char *key, *value;
 
-                        r = get_property_from_string(line, &key, &value);
+                        r = get_property_from_string(*line, &key, &value);
                         if (r < 0) {
                                 log_rule_debug_errno(dev, rules, r,
                                                      "Failed to parse key and value from '%s', ignoring: %m",
-                                                     line);
+                                                     *line);
                                 continue;
                         }
                         if (r == 0)