From: dongshengyuan <545258830@qq.com> Date: Thu, 9 Jul 2026 12:30:44 +0000 (+0800) Subject: udev: require exact builtin command matches X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0c5ba9662962406e661d2c8e15ef64a45511fec;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c index fbed496c4ec..de284d60fea 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 18326c03ad8..c0bd2b1565d 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")