* [musl] hasmntopt function returns non-NULL when it shouldn't
@ 2024-08-19 14:46 Bruno Haible
0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2024-08-19 14:46 UTC (permalink / raw)
To: musl
Hi,
The hasmntopt() function is documented in
https://www.gnu.org/software/libc/manual/html_node/mtab.html
and
https://man7.org/linux/man-pages/man3/hasmntopt.3.html
The implementation of this function in musl libc 1.2.5 returns a non-NULL
value also for some options that do *not* occur in the mount options string.
How to reproduce:
=============================== has.c ===============================
#include <mntent.h>
#include <string.h>
#include <assert.h>
int
main ()
{
char options[] = "rw,nosuid,nodev,noexec,noatime,size=5120k,inode64";
struct mntent me;
me.mnt_opts = options;
assert (hasmntopt (&me, "ro") == NULL);
assert (hasmntopt (&me, "rw") == options + 0);
assert (hasmntopt (&me, "atime") == NULL);
assert (hasmntopt (&me, "no") == NULL);
assert (hasmntopt (&me, "noatime") == options + 23);
assert (hasmntopt (&me, "size") == options + 31);
assert (hasmntopt (&me, "size=512") == NULL);
assert (hasmntopt (&me, "size=5120k") == options + 31);
assert (hasmntopt (&me, "inode64") == options + 42);
return 0;
}
=====================================================================
$ gcc -Wall has.c
$ ./a.out
Expected result: No assertion failure. Like on glibc.
Actual result:
Assertion failed: hasmntopt (&me, "atime") == NULL (has.c: main: 14)
The mount options "atime" and "noatime" are pretty much the opposite of
each other (see https://man7.org/linux/man-pages/man8/mount.8.html).
Therefore in a program that tests for the "atime" option, it is wrong
to return the equivalent of true when the options string contains "noatime",
not "atime".
Bruno
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-08-19 14:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-19 14:46 [musl] hasmntopt function returns non-NULL when it shouldn't Bruno Haible
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).