sysupdate: Check that --instances-max is in bounds

Otherwise user can pass in --instances-max=0 and crash sysupdate with an
assertion failure.
This commit is contained in:
Adrian Vovk
2024-08-22 16:00:44 -04:00
parent 7934803634
commit 0402bf682f
2 changed files with 11 additions and 3 deletions
+8
View File
@@ -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 */