mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Oliver Ford <ojford@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH musl v2 3/3] mntent: fix parsing lines with optional fields
Date: Thu, 12 May 2022 17:10:15 -0400	[thread overview]
Message-ID: <20220512211014.GL7074@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAGMVOduojZiBk_oy5aUhc3RkiKPZHvSYN=2qXArHPQ34RziX1A@mail.gmail.com>

On Thu, May 12, 2022 at 09:58:30PM +0100, Oliver Ford wrote:
> On Thu, May 12, 2022 at 3:08 PM Rich Felker <dalias@libc.org> wrote:
> >
> > - There's also an independent bug in hasmntent that was reported a
> >   long time ago then lost: it will return false positives when one
> >   mntopt name is a substring of another. strstr is just not the right
> >   operation here, at least not without added logic to ensure matching
> >   on a whole option boundary. This is a separate issue that calls for
> >   a separate patch though, not a blocker on the patch under discussion
> >   here.
> >
> Looking at this, the "hasmntopt" function does match options where the
> string is part of the option but not the whole option. So the opt "ro"
> will correctly match the "ro" (for read-only) option, but also match
> an option that contains "symlinkroot".
> 
> The following version of the function keeps the initial strstr, but
> adds an extra check so that it doesn't match unless the next character
> is either a comma or nul. If there's no other special cases we need to
> handle, I'll submit as a
> patch?
> 
> char *hasmntopt(const struct mntent *mnt, const char *opt)
> {
>         char *op = strstr(mnt->mnt_opts, opt);
> 
>         if (op == NULL) return NULL;
>         size_t len = strlen(opt);
>         char *end = op + len;
>         if (*end == '\0' || *end == ',') return op;
> 
>         return NULL;
> }

This fails to check that the match is at the start of an option
(preceded by a ',' or at the beginning of string) and fails to
continue if the first match is a false positive (e.g. "ro" in
"symlinkroot,ro"). It's possible to solve this still using strstr in a
loop, but it might be easier to just iterate delimiters and strcmp.

Also, I'm not sure if hasmntopt is supposed to return a match or not
for something like "uid" in "uid=1001"; if so, being followed by '='
also needs to be considered valid match.

Rich

  reply	other threads:[~2022-05-12 21:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15 22:11 [musl] [PATCH v2 0/3] Alyssa Ross
2021-09-15 22:11 ` [musl] [PATCH libc-test v2 1/3] functional: add mntent test Alyssa Ross
2021-09-15 22:11 ` [musl] [PATCH libc-test v2 2/3] functional: add mntent test for single-field line Alyssa Ross
2021-09-15 22:11 ` [musl] [PATCH musl v2 3/3] mntent: fix parsing lines with optional fields Alyssa Ross
2021-09-20  4:21   ` Rich Felker
2022-01-09  3:18     ` Rich Felker
2022-01-13 16:30       ` Alyssa Ross
2022-01-13 17:40         ` Rich Felker
2022-01-13 18:53           ` Alyssa Ross
2022-05-12 14:08             ` Rich Felker
2022-05-12 18:02               ` Alyssa Ross
2022-05-12 18:15                 ` Rich Felker
2022-05-15 18:38                   ` Alyssa Ross
2022-05-15 23:19                     ` Rich Felker
2022-05-16 10:19                       ` Alyssa Ross
2022-05-12 20:58               ` Oliver Ford
2022-05-12 21:10                 ` Rich Felker [this message]
2022-05-13 21:39                   ` Oliver Ford
2022-05-14  4:24                     ` Rich Felker
2022-05-14 22:16                       ` Oliver Ford
2022-05-15 23:31               ` Rich Felker
2022-05-16 10:07                 ` Alyssa Ross

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=20220512211014.GL7074@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=ojford@gmail.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).