From: Yu Watanabe Date: Thu, 21 Jan 2021 05:14:11 +0000 (+0900) Subject: udev: use strv_split_newlines() to parse result of spawned command X-Git-Tag: v248-rc1~188^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28a5065149c31a8689738ddcd1100502371a7c34;p=thirdparty%2Fsystemd.git udev: use strv_split_newlines() to parse result of spawned command --- diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index e72013ea56f..a87c5d119e6 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -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)