]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: require exact builtin command matches
authordongshengyuan <545258830@qq.com>
Thu, 9 Jul 2026 12:30:44 +0000 (20:30 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 10 Jul 2026 11:41:13 +0000 (20:41 +0900)
Commit 9b917abe02505d4ad09c4963ec5a4b2744eb2fee (udev-builtin:
simplify code a bit) changed builtin lookup from copying the first
command word and comparing it with streq() to comparing only the first
command word length with strneq().

That made prefixes such as "k" or "key" resolve to the "keyboard"
builtin, depending on the builtins table order. This was not the
original behavior.

Require the matched builtin name to end at the first command word
boundary so only complete builtin names are accepted. Arguments after
the builtin name continue to work as before.

src/udev/udev-builtin.c
test/units/TEST-17-UDEV.sanity-check.sh

index fbed496c4ec4021280d73e9822deb0267a5f8690..de284d60feae72744f2b79223d567e997469adfb 100644 (file)
@@ -105,7 +105,9 @@ UdevBuiltinCommand udev_builtin_lookup(const char *command) {
         command += strspn(command, WHITESPACE);
         n = strcspn(command, WHITESPACE);
         for (UdevBuiltinCommand i = 0; i < _UDEV_BUILTIN_MAX; i++)
-                if (builtins[i] && strneq(builtins[i]->name, command, n))
+                if (builtins[i] &&
+                    strlen(builtins[i]->name) == n &&
+                    strneq(builtins[i]->name, command, n))
                         return i;
 
         return _UDEV_BUILTIN_INVALID;
index 18326c03ad8f45acaf791edee3f0cda75ced2142..c0bd2b1565dd1ab6a056a69d52c878781b9f4c8d 100755 (executable)
@@ -178,6 +178,8 @@ udevadm test -h
 
 # Builtins
 (! udevadm test-builtin aaaaa /dev/null)
+(! udevadm test-builtin k /dev/null)
+(! udevadm test-builtin key /dev/null)
 udevadm test-builtin blkid "$loopdev"
 (! udevadm test-builtin "btrfs" "$loopdev")
 (! udevadm test-builtin "btrfs aaaaa" "$loopdev")