From: Oliver Ford <ojford@gmail.com>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH musl v2 3/3] mntent: fix parsing lines with optional fields
Date: Sat, 14 May 2022 23:16:14 +0100 [thread overview]
Message-ID: <CAGMVOdsP6Acso-S0f0bLBFtXd78xCJWUmrfN4W+czWJYMhJA6g@mail.gmail.com> (raw)
In-Reply-To: <20220514042409.GO7074@brightrain.aerifal.cx>
On Sat, May 14, 2022 at 5:24 AM Rich Felker <dalias@libc.org> wrote:
> This has UB unless ptr points to at least len bytes. You can only
> evaluate ptr+len or ptr[len] after confirming that. The strncmp is the
> most natural (and free) way of confirming it. You could assign end
> after the strncmp but I think just using ptr[len] instead of *end
> makes it easier.
>
> > if (!strncmp(ptr, opt, len) &&
> > (*end == '\0' || *end == ',' || *end == '=')) return ptr;
> > ptr = strchr(ptr, ',');
> > if (ptr) ptr++;
> > }
> >
> > return NULL;
>
> Minor style nit: NULL is generally not used in musl anymore; just 0 is
> fine here.
>
> BTW you dropped the list from CC; I re-added it.
>
> Rich
Version below should be correct, now uses ptr[len] instead of the *end.
char *hasmntopt(const struct mntent *mnt, const char *opt)
{
char *ptr = mnt->mnt_opts;
size_t len = strlen(opt);
while (ptr) {
if (!strncmp(ptr, opt, len) &&
(ptr[len] == '\0' || ptr[len] == ',' || ptr[len] == '='))
return ptr;
ptr = strchr(ptr, ',');
if (ptr) ptr++;
}
return 0;
}
next prev parent reply other threads:[~2022-05-14 22:16 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
2022-05-13 21:39 ` Oliver Ford
2022-05-14 4:24 ` Rich Felker
2022-05-14 22:16 ` Oliver Ford [this message]
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=CAGMVOdsP6Acso-S0f0bLBFtXd78xCJWUmrfN4W+czWJYMhJA6g@mail.gmail.com \
--to=ojford@gmail.com \
--cc=dalias@libc.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).