summaryrefslogtreecommitdiff
path: root/libbcachefs/opts.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-05-15 14:43:26 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2021-05-15 14:43:26 -0400
commita76f36fc6e6af7a4ba8d440d84e2cd6b4ec0b88b (patch)
tree04142cb4572bf9f25ef894971857e2a64b03df3f /libbcachefs/opts.c
parentbf145974607928c32c14d27c5c57e1220cad195d (diff)
Update bcachefs sources to ae6f512de8 bcachefs: Fix out of bounds read in fs usage ioctl
Diffstat (limited to 'libbcachefs/opts.c')
-rw-r--r--libbcachefs/opts.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/libbcachefs/opts.c b/libbcachefs/opts.c
index 0cfbb56a..64bf5a38 100644
--- a/libbcachefs/opts.c
+++ b/libbcachefs/opts.c
@@ -315,11 +315,20 @@ int bch2_opts_check_may_set(struct bch_fs *c)
int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts,
char *options)
{
+ char *copied_opts, *copied_opts_start;
char *opt, *name, *val;
int ret, id;
u64 v;
- while ((opt = strsep(&options, ",")) != NULL) {
+ if (!options)
+ return 0;
+
+ copied_opts = kstrdup(options, GFP_KERNEL);
+ if (!copied_opts)
+ return -1;
+ copied_opts_start = copied_opts;
+
+ while ((opt = strsep(&copied_opts, ",")) != NULL) {
name = strsep(&opt, "=");
val = opt;
@@ -363,16 +372,24 @@ int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts,
bch2_opt_set_by_id(opts, id, v);
}
- return 0;
+ ret = 0;
+ goto out;
+
bad_opt:
pr_err("Bad mount option %s", name);
- return -1;
+ ret = -1;
+ goto out;
bad_val:
pr_err("Invalid value %s for mount option %s", val, name);
- return -1;
+ ret = -1;
+ goto out;
no_val:
pr_err("Mount option %s requires a value", name);
- return -1;
+ ret = -1;
+ goto out;
+out:
+ kfree(copied_opts_start);
+ return ret;
}
/* io opts: */