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.
This commit is contained in:
Yu Watanabe
2023-07-19 10:47:53 +09:00
committed by Daan De Meyer
parent e30c6e913c
commit 149aedb89b
2 changed files with 18 additions and 2 deletions

View File

@@ -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 },
{}
};

View File

@@ -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