From: Andrew Morton <akpm@linux-foundation.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>
Subject: Re: [PATCH] bootconfig: Fix off-by-one in xbc_node_compose_key_after()
Date: Thu, 13 Aug 2020 19:38:18 -0700 [thread overview]
Message-ID: <20200813193818.a44ea9afc447f57d470b2def@linux-foundation.org> (raw)
In-Reply-To: <20200813183050.029a6003@oasis.local.home>
On Thu, 13 Aug 2020 18:30:50 -0400 Steven Rostedt <rostedt@goodmis.org> wrote:
> From: Steven Rostedt (VMware) <rostedt@goodmis.org>
>
> While reviewing some patches for bootconfig, I noticed the following
> code in xbc_node_compose_key_after():
>
> ret = snprintf(buf, size, "%s%s", xbc_node_get_data(node),
> depth ? "." : "");
> if (ret < 0)
> return ret;
> if (ret > size) {
> size = 0;
> } else {
> size -= ret;
> buf += ret;
> }
>
> But snprintf() returns the number of bytes that would be written, not
> the number of bytes that are written (ignoring the nul terminator).
> This means that if the number of non null bytes written were to equal
> size, then the nul byte, which snprintf() always adds, will overwrite
> that last byte.
>
> ret = snprintf(buf, 5, "hello");
> printf("buf = '%s'\n", buf);
> printf("ret = %d\n", ret);
>
> produces:
>
> buf = 'hell'
> ret = 5
>
> The string was truncated without ret being greater than 5.
> Test (ret >= size) for overwrite.
What are the end-user visible effects of the bug? IOW, why cc:stable?
next prev parent reply other threads:[~2020-08-14 2:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-13 22:30 Steven Rostedt
2020-08-14 2:38 ` Andrew Morton [this message]
2020-08-14 3:04 ` Steven Rostedt
2020-08-15 11:28 ` Masami Hiramatsu
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=20200813193818.a44ea9afc447f57d470b2def@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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
all inboxes | Powered by JetHome®