]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit
mkfs: terminate getsubopt arrays properly
authorDarrick J. Wong <djwong@kernel.org>
Thu, 14 Jul 2022 01:58:28 +0000 (20:58 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 14 Jul 2022 01:58:28 +0000 (20:58 -0500)
commit50dba8189b1f628073eb61d824ae8a8a1b43cefb
tree8591b11cee592bb302fb36b6d6a217fbb83ab344
parent91c1d0836aa4a228e76c0b8c5d83903f1f6bfdbb
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.

Explicitly terminate each suboption array with a NULL entry after
making room for it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[sandeen: explicitly add NULL terminators & clarify comment]
Reviewed-by: Eric Sandeen <sandeen@sandeen.net>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
mkfs/xfs_mkfs.c