diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-07 01:44:00 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-07 20:38:19 +0200 |
commit | 2c5f119c3cc78bd7da0c7c56b57eca43bac464c1 (patch) | |
tree | 3dfc4b4d0996e3511bc98e158327f4fad0b6f1ee /src/udev | |
parent | udev-rules: replace ingrowing word extractor with extract_first_word() (diff) | |
download | systemd-2c5f119c3cc78bd7da0c7c56b57eca43bac464c1.tar.xz systemd-2c5f119c3cc78bd7da0c7c56b57eca43bac464c1.zip |
sd-device,udev: refuse invalid devlink and store in normalized form
This is especially for the case that the path contains "..".
Prompted by https://github.com/systemd/systemd/pull/27164#issuecomment-1498863858.
This also makes SYMLINK= gracefully handle paths prefixed with "/dev/",
and manage devlink paths with path_hash_ops.
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/udev-rules.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 58c5c81574..68f0a363be 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -2574,9 +2574,9 @@ static int udev_rule_apply_token_to_event( count, token->value); for (const char *p = buf;;) { - _cleanup_free_ char *word = NULL, *path = NULL; + _cleanup_free_ char *path = NULL; - r = extract_first_word(&p, &word, NULL, EXTRACT_RETAIN_ESCAPE); + r = extract_first_word(&p, &path, NULL, EXTRACT_RETAIN_ESCAPE); if (r == -ENOMEM) return log_oom(); if (r < 0) { @@ -2586,19 +2586,22 @@ static int udev_rule_apply_token_to_event( if (r == 0) break; - path = path_join("/dev/", word); - if (!path) - return log_oom(); - if (token->op == OP_REMOVE) { - device_remove_devlink(dev, path); - log_event_debug(dev, token, "Dropped SYMLINK '%s'", path); + r = device_remove_devlink(dev, path); + if (r == -ENOMEM) + return log_oom(); + if (r < 0) + log_event_warning_errno(dev, token, r, "Failed to remove devlink '%s', ignoring: %m", path); + else if (r > 0) + log_event_debug(dev, token, "Dropped SYMLINK '%s'", path); } else { r = device_add_devlink(dev, path); + if (r == -ENOMEM) + return log_oom(); if (r < 0) - return log_event_error_errno(dev, token, r, "Failed to add devlink '%s': %m", path); - - log_event_debug(dev, token, "Added SYMLINK '%s'", path); + log_event_warning_errno(dev, token, r, "Failed to add devlink '%s', ignoring: %m", path); + else if (r > 0) + log_event_debug(dev, token, "Added SYMLINK '%s'", path); } } break; |