]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: replace unsafe characters on assigning ENV{key}="val" when OPTIONS="string_esca...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 14 Apr 2021 06:13:54 +0000 (15:13 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jun 2021 07:40:52 +0000 (16:40 +0900)
Strictly speaking, this breaks backward compatibility, as previously
`ENV{key}="val"` ignored `string_escape=` option. But, introducing
a new option such as `string_escape=hoge` sounds overkill for me.
The default escape mode is `ESCAPE_UNSET`, so I hope this merely break
existing rules.

src/udev/udev-rules.c

index d34f9be39efa3072f53fa0aa0aeef784cfbf49a0..8713186226b6c0c7f6ff5654d442f87be408d128 100644 (file)
@@ -2024,6 +2024,12 @@ static int udev_rule_apply_token_to_event(
                         l = strpcpyl(&p, l, val, " ", NULL);
 
                 (void) udev_event_apply_format(event, token->value, p, l, false);
+                if (event->esc == ESCAPE_REPLACE) {
+                        count = udev_replace_chars(buf, NULL);
+                        if (count > 0)
+                                log_rule_debug(dev, rules, "Replaced %zu slash(es) from result of ENV{%s}%s=\"%s\"",
+                                               count, name, token->op == OP_ADD ? "+" : "", token->value);
+                }
 
                 r = device_add_property(dev, name, value_new);
                 if (r < 0)