Message ID | 20211217190902.GL27664@magnolia (mailing list archive) |
---|---|
State | Accepted, archived |
Headers | show |
Series | mkfs: prevent corruption of passed-in suboption string values | expand |
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 3a41e17f..fcad6b55 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1438,12 +1438,21 @@ getstr( struct opt_params *opts, int index) { + char *ret; + check_opt(opts, index, true); /* empty strings for string options are not valid */ if (!str || *str == '\0') reqval(opts->name, opts->subopts, index); - return (char *)str; + + ret = strdup(str); + if (!ret) { + fprintf(stderr, _("Out of memory while saving suboptions.\n")); + exit(1); + } + + return ret; } static int