From c0c5ba9662962406e661d2c8e15ef64a45511fec Mon Sep 17 00:00:00 2001 From: dongshengyuan <545258830@qq.com> Date: Thu, 9 Jul 2026 20:30:44 +0800 Subject: [PATCH] udev: require exact builtin command matches 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 | 4 +++- test/units/TEST-17-UDEV.sanity-check.sh | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c index fbed496c4e..de284d60fe 100644 --- a/src/udev/udev-builtin.c +++ b/src/udev/udev-builtin.c @@ -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; diff --git a/test/units/TEST-17-UDEV.sanity-check.sh b/test/units/TEST-17-UDEV.sanity-check.sh index 18326c03ad..c0bd2b1565 100755 --- a/test/units/TEST-17-UDEV.sanity-check.sh +++ b/test/units/TEST-17-UDEV.sanity-check.sh @@ -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")