mkfs: terminate getsubopt arrays properly
Having not drank any (or maybe too much) coffee this morning, I typed:
$ mkfs.xfs -d agcount=3 -d nrext64=0
Segmentation fault
I traced this down to getsubopt walking off the end of the dopts.subopts
array. The manpage says you're supposed to terminate the suboptions
string array with a NULL entry, but the structure definition uses
MAX_SUBOPTS/D_MAX_OPTS directly, which means there is no terminator.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 61ac1a4..9a58ff8 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -141,7 +141,7 @@
};
/* Just define the max options array size manually right now */
-#define MAX_SUBOPTS D_MAX_OPTS
+#define MAX_SUBOPTS (D_MAX_OPTS + 1)
#define SUBOPT_NEEDS_VAL (-1LL)
#define MAX_CONFLICTS 8