mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] hasmntopt(3) match options instead of substring?
@ 2025-02-03 23:46 Sertonix
  2025-02-09 14:37 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Sertonix @ 2025-02-03 23:46 UTC (permalink / raw)
  To: musl

Hi,

people reported issues with mount options not working correctly with
ZFS[1] and someone noticed that it could be related to a behaviour
difference of hasmntopt(3) between musl and glibc.

The manpage[2] mentions that it returns a "substring that matches opt".
Just like musl has implemented it this is just strstr. The problem is
that it will return "atime" as a option found in "noatime" even though
that is probably not what people want.

glibc only accepts matches that match the complete option name.[3]

Would it be possible for musl to only match options as well?
Ideally the wording of hasmntopt(3) would be improved too.

[1]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/12382
[2]: https://man.archlinux.org/man/hasmntopt.3.en
[3]: https://codebrowser.dev/glibc/glibc/misc/mntent_r.c.html#__hasmntopt

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [musl] hasmntopt(3) match options instead of substring?
  2025-02-03 23:46 [musl] hasmntopt(3) match options instead of substring? Sertonix
@ 2025-02-09 14:37 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2025-02-09 14:37 UTC (permalink / raw)
  To: Sertonix; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

On Mon, Feb 03, 2025 at 11:46:06PM +0000, Sertonix wrote:
> Hi,
> 
> people reported issues with mount options not working correctly with
> ZFS[1] and someone noticed that it could be related to a behaviour
> difference of hasmntopt(3) between musl and glibc.
> 
> The manpage[2] mentions that it returns a "substring that matches opt".
> Just like musl has implemented it this is just strstr. The problem is
> that it will return "atime" as a option found in "noatime" even though
> that is probably not what people want.
> 
> glibc only accepts matches that match the complete option name.[3]
> 
> Would it be possible for musl to only match options as well?
> Ideally the wording of hasmntopt(3) would be improved too.
> 
> [1]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/12382
> [2]: https://man.archlinux.org/man/hasmntopt.3.en
> [3]: https://codebrowser.dev/glibc/glibc/misc/mntent_r.c.html#__hasmntopt

This was reported back in
https://www.openwall.com/lists/musl/2023/03/30/5 and probably sometime
earlier as well, and I think we're in agreement that it needs to be
changed.

Here's a completely untested patch which I think gives the reasonable
and glibc-matching behavior.

Rich

[-- Attachment #2: hasmntopt.diff --]
[-- Type: text/plain, Size: 513 bytes --]

diff --git a/src/misc/mntent.c b/src/misc/mntent.c
index ee17a69f..93a68eb0 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);
+	const 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++;
+	}
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-09 14:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-03 23:46 [musl] hasmntopt(3) match options instead of substring? Sertonix
2025-02-09 14:37 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).