[PATCH] xfsprogs: properly check size arguments for growfs

Guangyu Sun guangyu.sun at oracle.com
Thu Nov 14 13:50:08 CST 2013


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 at oracle.com>
Signed-off-by: Guangyu Sun <guangyu.sun at 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



More information about the xfs mailing list