Skip to contentSkip to conversation

xfsprogs: properly check size arguments for growfs

PATCH In review Guangyu Sun 2 participants 2 messages Nov 14, 2013 – Nov 17, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfsprogs: properly check size arguments for growfs

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
---
 growfs/xfs_growfs.c |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
growfs/xfs_growfs.c +19 -3
index 2df68fb..bcadd84 100644
@@ -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;
Signature · 6 lines
1.7.9.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 22 lines · 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
Quoted 2 lines

Perhaps this should be changed to use cvtnum() from libxcmd? That will fix the input validation problem, and also allow xfs_growfs to all the different methods of specifying size that we use elsewhere in xfsprogs...

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs