]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sfdisk: reject spurious arguments for --reorder/--backup-pt-sectors
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 24 Aug 2025 09:45:45 +0000 (11:45 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 24 Aug 2025 09:45:45 +0000 (11:45 +0200)
These commands only accept a single device argument.
Reject any additional unexpected arguments.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
disk-utils/sfdisk.c

index ad9bbb3cf8ad8cb0d1dc1265694c24b227139000..b754916efd73cbd83792aa942223b4351ddff119 100644 (file)
@@ -1025,13 +1025,14 @@ static int command_delete(struct sfdisk *sf, int argc, char **argv)
  */
 static int command_reorder(struct sfdisk *sf, int argc, char **argv)
 {
-       const char *devname = NULL;
+       const char *devname;
        int rc;
 
-       if (argc)
-               devname = argv[0];
-       if (!devname)
+       if (!argc)
                errx(EXIT_FAILURE, _("no disk device specified"));
+       devname = argv[0];
+       if (argc > 1)
+               errx(EXIT_FAILURE, _("unexpected arguments"));
 
        assign_device(sf, devname, 0);  /* read-write */
 
@@ -1049,14 +1050,15 @@ static int command_reorder(struct sfdisk *sf, int argc, char **argv)
  */
 static int command_dump(struct sfdisk *sf, int argc, char **argv)
 {
-       const char *devname = NULL;
        struct fdisk_script *dp;
+       const char *devname;
        int rc;
 
-       if (argc)
-               devname = argv[0];
-       if (!devname)
+       if (!argc)
                errx(EXIT_FAILURE, _("no disk device specified"));
+       devname = argv[0];
+       if (argc > 1)
+               errx(EXIT_FAILURE, _("unexpected arguments"));
 
        assign_device(sf, devname, 1);  /* read-only */
 
@@ -1085,12 +1087,13 @@ static int command_dump(struct sfdisk *sf, int argc, char **argv)
  */
 static int command_backup_sectors(struct sfdisk *sf, int argc, char **argv)
 {
-       const char *devname = NULL;
+       const char *devname;
 
-       if (argc)
-               devname = argv[0];
-       if (!devname)
+       if (!argc)
                errx(EXIT_FAILURE, _("no disk device specified"));
+       devname = argv[0];
+       if (argc > 1)
+               errx(EXIT_FAILURE, _("unexpected arguments"));
 
        assign_device(sf, devname, 1);  /* read-only */