summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2025-02-09 13:36:44 -0500
committerRich Felker <dalias@aerifal.cx>2025-02-09 13:36:44 -0500
commit4c4f15dae57125e5b65b9690901384ae501d38e2 (patch)
tree59e5c51febb80ec17946212e0433810532e15715
parente5adcd97b5196e29991b524237381a0202a60659 (diff)
downloadmusl-4c4f15dae57125e5b65b9690901384ae501d38e2.tar.gz
hasmntopt: match only whole options not arbitrary substrings
the man page for this nonstandardized function has historically documented it as scanning for a substring; however, this is functionally incorrect (matches the substring "atime" in the "noatime" option, for example) and differs from other existing implementations. with the change made here, it should match glibc and other implementations, only matching whole options delimited by commas or separated from a value by an equals sign.
-rw-r--r--src/misc/mntent.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/misc/mntent.c b/src/misc/mntent.c
index ee17a69f..76f9c162 100644
--- a/src/misc/mntent.c
+++ b/src/misc/mntent.c
@@ -115,5 +115,13 @@ int addmntent(FILE *f, const struct mntent *mnt)
char *hasmntopt(const struct mntent *mnt, const char *opt)
{
- return strstr(mnt->mnt_opts, opt);
+ size_t l = strlen(opt);
+ char *p = mnt->mnt_opts;
+ for (;;) {
+ if (!strncmp(p, opt, l) && (!p[l] || p[l]==',' || p[l]=='='))
+ return p;
+ p = strchr(p, ',');
+ if (!p) return 0;
+ p++;
+ }
}