diff options
author | helg <helg@cvs.openbsd.org> | 2017-12-11 12:01:56 +0000 |
---|---|---|
committer | helg <helg@cvs.openbsd.org> | 2017-12-11 12:01:56 +0000 |
commit | 5c86e84ed2fc7dfc54a2dd42491cd11e26629f79 (patch) | |
tree | cdf12d1b63cd0094752e0fd533755d8e0b1f0cf2 /lib/libfuse | |
parent | 2868b8d6cd10181dc07d4214f7e356cb7c36e466 (diff) |
The fuse_opt_match(3) library function does not match options correctly.
libfuse supports option templates of the following form that can be used
to automatically parse arguments supplied on the command line.
"-p " argument that takes an option e.g -p 22 or -p22
"-p %x" argument that takes an option parsed like sscanf(3)
"cache=yes" matches -ocache=yes or -o cache=yes
"cache=%s" matches -ocache=<string> or -o cache=<string>
"cache=" matches same as above but value is passed to option proc
"noatime" matches -onoatime or -o atime
For example, it does not match options of the form "-p 22" or
"cache=yes" to the corresponding templates "-p " and "cache=yes". This
patch fixes that and updates the regression tests accordingly.
ok mpi@
Diffstat (limited to 'lib/libfuse')
-rw-r--r-- | lib/libfuse/fuse_opt.c | 76 |
1 files changed, 19 insertions, 57 deletions
diff --git a/lib/libfuse/fuse_opt.c b/lib/libfuse/fuse_opt.c index 873b3380399..0b026cc6038 100644 --- a/lib/libfuse/fuse_opt.c +++ b/lib/libfuse/fuse_opt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_opt.c,v 1.19 2017/11/16 12:56:58 helg Exp $ */ +/* $OpenBSD: fuse_opt.c,v 1.20 2017/12/11 12:01:55 helg Exp $ */ /* * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com> * Copyright (c) 2013 Stefan Sperling <stsp@openbsd.org> @@ -67,73 +67,35 @@ alloc_argv(struct fuse_args *args) return (0); } -static int +/* + * Returns the number of characters that matched for bounds checking later. + */ +static size_t match_opt(const char *templ, const char *opt) { - const char *o, *t; - char *arg; - - arg = strpbrk(templ, " ="); - - /* verify template */ - t = templ; - if (*t == '-') { - t++; - if (*t == '-') - t++; - if (*t == 'o' || *t == '\0') - return (0); - } + size_t sep, len; - /* skip leading -, -o, and -- in option name */ - o = opt; - if (*o == '-') { - o++; - if (*o == 'o' || *o == '-') - o++; - } + len = strlen(templ); + sep = strcspn(templ, "="); - /* empty option name is invalid */ - if (*o == '\0') - return (0); + if (sep == len) + sep = strcspn(templ, " "); - /* match option name */ - while (*t && *o) { - if (*t++ != *o++) + /* key=, key=%, "-k ", -k % */ + if (sep < len && (templ[sep + 1] == '\0' || templ[sep + 1] == '%')) { + if (strncmp(opt, templ, sep) == 0) + return (sep); + else return (0); - if (arg && t == arg) { - if (*o != ' ' && *o != '=') - return (0); - o++; /* o now points at argument */ - if (*o == '\0') - return (0); - break; - } } - /* match argument */ - if (arg) { - if (t != arg) - return (0); - t++; - /* does template have an argument? */ - if (*t != '%' && *t != '\0') - return (0); - if (*t == '%' && t[1] == '\0') - return (0); - /* yes it does, consume argument in opt */ - while (*o && *o != ' ') - o++; - } else if (*t != '\0') - return (0); + if (strcmp(opt, templ) == 0) + return (len); - /* we should have consumed entire opt string */ - if (*o != '\0') - return (0); - - return (1); + return (0); } + static int add_opt(char **opts, const char *opt) { |