Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 12 May 2022 21:58:30 +0100
From: Oliver Ford <ojford@...il.com>
To: musl@...ts.openwall.com
Subject: Re: [PATCH musl v2 3/3] mntent: fix parsing lines with
 optional fields

On Thu, May 12, 2022 at 3:08 PM Rich Felker <dalias@...c.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;
}

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.