From: Yu Watanabe Date: Wed, 19 Jul 2023 01:47:53 +0000 (+0900) Subject: kernel-install: silently ignore unexpected arguments for 'remove' command X-Git-Tag: v254-rc3~27 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=149aedb89b66f47f9a13cdc41ec00e3e4f0f213d;p=thirdparty%2Fsystemd.git kernel-install: silently ignore unexpected arguments for 'remove' command The shell script version of kernel-install silently ignored unexpected arguments, but C version refused that. Unfortunately, Fedora's kernel script specifies kernel file even for 'remove' command. Let's accept extra arguments and silently ignore them to keep backward compatibility. Fixes #28448. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2223794. --- diff --git a/src/kernel-install/kernel-install.c b/src/kernel-install/kernel-install.c index 0acd8ebaa81..c573228991e 100644 --- a/src/kernel-install/kernel-install.c +++ b/src/kernel-install/kernel-install.c @@ -1041,9 +1041,13 @@ static int verb_remove(int argc, char *argv[], void *userdata) { Context *c = ASSERT_PTR(userdata); int r; - assert(argc == 2); + assert(argc >= 2); assert(argv); + if (argc > 2) + log_debug("Too many arguments specified. 'kernel-install remove' takes only kernel version. " + "Ignoring residual arguments."); + c->action = ACTION_REMOVE; r = context_set_version(c, argv[1]); @@ -1220,7 +1224,7 @@ static int parse_argv(int argc, char *argv[], Context *c) { static int run(int argc, char* argv[]) { static const Verb verbs[] = { { "add", 3, VERB_ANY, 0, verb_add }, - { "remove", 2, 2, 0, verb_remove }, + { "remove", 2, VERB_ANY, 0, verb_remove }, { "inspect", 1, 2, VERB_DEFAULT, verb_inspect }, {} }; diff --git a/src/kernel-install/test-kernel-install.sh b/src/kernel-install/test-kernel-install.sh index b7b7eae7e1d..aa0881a6e07 100755 --- a/src/kernel-install/test-kernel-install.sh +++ b/src/kernel-install/test-kernel-install.sh @@ -71,6 +71,18 @@ test ! -e "$entry" test ! -e "$BOOT_ROOT/the-token/1.1.1/linux" test ! -e "$BOOT_ROOT/the-token/1.1.1/initrd" +# Test again with too many arguments for 'remove' command. See #28448. +"$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd" + +test -f "$entry" +test -f "$BOOT_ROOT/the-token/1.1.1/linux" +test -f "$BOOT_ROOT/the-token/1.1.1/initrd" + +"$kernel_install" -v remove 1.1.1 hoge foo bar +test ! -e "$entry" +test ! -e "$BOOT_ROOT/the-token/1.1.1/linux" +test ! -e "$BOOT_ROOT/the-token/1.1.1/initrd" + # Invoke kernel-install as installkernel ln -s --relative -v "$kernel_install" "$D/sources/installkernel" "$D/sources/installkernel" -v 1.1.2 "$D/sources/linux" System.map /somedirignored