From: "Sören Tempel" <soeren@soeren-tempel.net>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH v2] libmount: Fix access to uninitialised value in mnt_optstr_locate_option
Date: Mon, 27 Feb 2023 20:00:55 +0100 [thread overview]
Message-ID: <2B71FNQUV107Y.2UPOBHSWLST8P@8pit.net> (raw)
In-Reply-To: <20230227105038.l2pw3nn6x62tridi@ws.net.home>
Hey Karel,
Thanks for your patch, the changes look good to me!
I have one small follow-up question though. You added the following
sentence to the documentation for mnt_match_options():
> The alone "no" is error and all matching ends with False.
I believe this to be a good change. However, If my understanding of
this documentation comment is correct I would have expected
mnt_match_options("bla", "no,,")
to return False as well but to my surprise it actually returns True. I
understand that this is an edge case but is that intended? Maybe the ","
should be treated as an terminating character for the "no" as well (i.e.
in addition to the null byte)?
diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
index 4fbbb0859..a0056c767 100644
--- a/libmount/src/optstr.c
+++ b/libmount/src/optstr.c
@@ -865,7 +865,7 @@ int mnt_match_options(const char *optstr, const char *pattern)
name++, namesz--;
else if ((no = (startswith(name, "no") != NULL))) {
name += 2, namesz -= 2;
- if (!*name) {
+ if (!*name || *name == ',') {
match = 0;
break; /* alone "no" keyword is error */
}
With this patch applied it also returns False for the "no,," pattern.
Greetings,
Sören
Karel Zak <kzak@redhat.com> wrote:
> On Sat, Feb 25, 2023 at 02:40:52PM +0100, Sören Tempel wrote:
> > This solution also has the issue that it handles the case incorrectly
> > where xstrncpy actually calls strlen(3). I wanted to avoid that but
> > maybe the best solution is to just change the xstrncpy API in a way that
> > it indicates whether it has written anything through an int return
> > value?
>
> The best will be to avoid all the buffer, xstrndup(), and
> mnt_optstr_get_option() using if the options string or the pattern is
> empty. It's unnecessary because we know that mnt_optstr_get_option()
> will return nothing.
>
> I have committed
> https://github.com/util-linux/util-linux/commit/06ee5267516761721ebfbdfa313980cef8e54c66
>
> > Sorry for all the noise. Next time, I will just write a bug report...
>
> That's no problem. We should be friendly to people who invest time to
> report bugs and write code ;-)
>
> Karel
next prev parent reply other threads:[~2023-02-27 19:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-25 11:43 [PATCH] libmount: Fix access to uninitialised value in mnt_optstr_locate_option soeren
2023-02-25 12:41 ` [PATCH v2] " soeren
2023-02-25 13:40 ` Sören Tempel
2023-02-27 10:50 ` Karel Zak
2023-02-27 19:00 ` Sören Tempel [this message]
2023-02-28 11:02 ` Karel Zak
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=2B71FNQUV107Y.2UPOBHSWLST8P@8pit.net \
--to=soeren@soeren-tempel.net \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox