From 4c4f15dae57125e5b65b9690901384ae501d38e2 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Feb 2025 13:36:44 -0500 Subject: 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. --- src/misc/mntent.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/misc') 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++; + } } -- cgit v1.2.1