public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfsprogs: properly check size arguments for growfs
@ 2013-11-14 19:50 Guangyu Sun
  2013-11-14 19:59 ` guangyu
  0 siblings, 1 reply; 2+ messages in thread
From: Guangyu Sun @ 2013-11-14 19:50 UTC (permalink / raw)
  To: xfs; +Cc: Koen De Wit, Guangyu Sun

xfs_growfs has lowercase options to grow a filesystem as big as possible
(e.g. the -d option) and uppercase options to grow a filesystem to a
specified size, expressed in blocks. (e.g. the "-D size" option)

If the size parameter is not numerical, the parameter is either trimmed or
ignored. In the latter case, the filesystem is grown as big as possible. This
may happen when users accidentally specify the size in a format similar to
mkfs.xfs (e.g. "-D 100m" or "-D size=16384")

In both cases, xfs_growfs should return an error instead of resizing the
filesystem.

To reproduce:
  # mkfs.xfs -f -d size=20m -L koenfs /dev/dm-3
  # mount /dev/dm-3 //mnt
  # xfs_growfs -D 10000andmorethan10invalidcharacters /mnt
  (...)
  data blocks changed from 5120 to 10000
  # xfs_growfs -D invalidargument20000containingnumbers /mnt
  (...)
  data blocks changed from 10000 to 19659543

Reported-by: Koen De Wit <koen.de.wit@oracle.com>
Signed-off-by: Guangyu Sun <guangyu.sun@oracle.com>
---
 growfs/xfs_growfs.c |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
index 2df68fb..4ed8eb8 100644
--- a/growfs/xfs_growfs.c
+++ b/growfs/xfs_growfs.c
@@ -123,6 +123,7 @@ main(int argc, char **argv)
 	int			projid32bit;
 	int			crcs_enabled;
 	int			ftype_enabled = 0;
+	char			*endptr;
 
 	progname = basename(argv[0]);
 	setlocale(LC_ALL, "");
@@ -137,7 +138,12 @@ main(int argc, char **argv)
 	while ((c = getopt(argc, argv, "dD:e:ilL:m:np:rR:t:xV")) != EOF) {
 		switch (c) {
 		case 'D':
-			dsize = strtoll(optarg, NULL, 10);
+			dsize = strtoll(optarg, &endptr, 10);
+			if (endptr) {
+				fprintf(stderr, _("%s: %s is not a valid "
+					"number\n"), progname, optarg);
+				return 1;
+			}
 			/* fall through */
 		case 'd':
 			dflag = 1;
@@ -150,7 +156,12 @@ main(int argc, char **argv)
 			lflag = iflag = 1;
 			break;
 		case 'L':
-			lsize = strtoll(optarg, NULL, 10);
+			lsize = strtoll(optarg, &endptr, 10);
+			if (endptr) {
+				fprintf(stderr, _("%s: %s is not a valid "
+					"number\n"), progname, optarg);
+				return 1;
+			}
 			/* fall through */
 		case 'l':
 			lflag = 1;
@@ -166,7 +177,12 @@ main(int argc, char **argv)
 			progname = optarg;
 			break;
 		case 'R':
-			rsize = strtoll(optarg, NULL, 10);
+			rsize = strtoll(optarg, &endptr, 10);
+			if (endptr) {
+				fprintf(stderr, _("%s: %s is not a valid "
+					"number\n"), progname, optarg);
+				return 1;
+			}
 			/* fall through */
 		case 'r':
 			rflag = 1;
-- 
1.7.9.5

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-14 19:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-14 19:50 [PATCH] xfsprogs: properly check size arguments for growfs Guangyu Sun
2013-11-14 19:59 ` guangyu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox