From: Bruno Haible <bruno@clisp.org>
To: musl@lists.openwall.com
Subject: [musl] hasmntopt function returns non-NULL when it shouldn't
Date: Mon, 19 Aug 2024 16:46:23 +0200 [thread overview]
Message-ID: <7665137.oDFzTOozpa@nimes> (raw)
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
reply other threads:[~2024-08-19 14:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7665137.oDFzTOozpa@nimes \
--to=bruno@clisp.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).