udev: require exact builtin command matches

Commit 9b917abe02 (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.
This commit is contained in:
dongshengyuan
2026-07-10 20:41:13 +09:00
committed by Yu Watanabe
parent 71bc8f4fe5
commit c0c5ba9662
2 changed files with 5 additions and 1 deletions
+3 -1
View 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;
+2
View File
@@ -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")