Re: fallocate: --punch option parsing error diagnostics irritating

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/26/2014 01:07 PM, Karel Zak wrote:
  Applied, thanks.

Thanks!

Now, the optind check is too late in those 2 invalid cases:

  $ ./fallocate
  fallocate: no length argument specified

  $ ./fallocate file1 file2
  fallocate: no length argument specified

The patch below fixes it.

BTW: I think fallocate(1) shouldn't open(...,O_CREAT)
with -d, -p, and maybe with -z, should it?

Have a nice day,
Berny

From d4b880a188517e12aead021bcee01630e2893e03 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 26 Jun 2014 14:09:47 +0200
Subject: [PATCH] fallocate: fix check of number of arguments

Signed-off-by: Bernhard Voelker <mail@xxxxxxxxxxxxxxxxxxx>
---
 sys-utils/fallocate.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c
index 91dee41..5abe3eb 100644
--- a/sys-utils/fallocate.c
+++ b/sys-utils/fallocate.c
@@ -339,6 +339,15 @@ int main(int argc, char **argv)
 			break;
 		}
 	}
+
+	if (optind == argc)
+		errx(EXIT_FAILURE, _("no filename specified"));
+
+	filename = argv[optind++];
+
+	if (optind != argc)
+		errx(EXIT_FAILURE, _("unexpected number of arguments"));
+
 	if (dig) {
 		/* for --dig-holes the default is analyze all file */
 		if (length == -2LL)
@@ -354,15 +363,6 @@ int main(int argc, char **argv)
 	}
 	if (offset < 0)
 		errx(EXIT_FAILURE, _("invalid offset value specified"));
-	if (optind == argc)
-		errx(EXIT_FAILURE, _("no filename specified."));
-
-	filename = argv[optind++];
-
-	if (optind != argc) {
-		warnx(_("unexpected number of arguments"));
-		usage(stderr);
-	}

 	fd = open(filename, O_RDWR|O_CREAT, 0644);
 	if (fd < 0)
--
1.8.4.2
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux