From: Adrian Vovk Date: Sat, 22 Jun 2024 00:49:48 +0000 (-0400) Subject: sysupdate: Check that --instances-max is in bounds X-Git-Tag: v257-rc1~616^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0402bf682fb3b11bd4fd36969abf5426f24c3dde;p=thirdparty%2Fsystemd.git sysupdate: Check that --instances-max is in bounds Otherwise user can pass in --instances-max=0 and crash sysupdate with an assertion failure. --- diff --git a/man/systemd-sysupdate.xml b/man/systemd-sysupdate.xml index dffe835c04a..f57a17b79ac 100644 --- a/man/systemd-sysupdate.xml +++ b/man/systemd-sysupdate.xml @@ -257,9 +257,9 @@ - Takes a decimal integer greater than or equal to 2. Controls how many versions to - keep at any time. This option may also be configured inside the transfer files, via the - InstancesMax= setting, see + Takes a decimal integer greater than or equal to 2 while updating or 1 while vacuuming. + Controls how many versions to keep at any time. This option may also be configured inside the transfer + files, via the InstancesMax= setting, see sysupdate.d5 for details. diff --git a/src/sysupdate/sysupdate.c b/src/sysupdate/sysupdate.c index dee8348bdb8..58545354276 100644 --- a/src/sysupdate/sysupdate.c +++ b/src/sysupdate/sysupdate.c @@ -1067,6 +1067,10 @@ static int verb_vacuum(int argc, char **argv, void *userdata) { assert(argc <= 1); + if (arg_instances_max < 1) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "The --instances-max argument must be >= 1 while vacuuming"); + r = process_image(/* ro= */ false, &mounted_dir, &loop_device); if (r < 0) return r; @@ -1090,6 +1094,10 @@ static int verb_update(int argc, char **argv, void *userdata) { assert(argc <= 2); version = argc >= 2 ? argv[1] : NULL; + if (arg_instances_max < 2) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "The --instances-max argument must be >= 2 while updating"); + if (arg_reboot) { /* If automatic reboot on completion is requested, let's first determine the currently booted image */