From: Andrew Jones <drjones@redhat.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] perf tools: Fix strbuf_addf() when the buffer needs to grow
Date: Wed, 24 Oct 2012 09:49:42 +0200 [thread overview]
Message-ID: <20121024074941.GB2227@turtle.usersys.redhat.com> (raw)
In-Reply-To: <1350999890-6920-2-git-send-email-namhyung@kernel.org>
On Tue, Oct 23, 2012 at 10:44:50PM +0900, Namhyung Kim wrote:
> This was found during chasing down the header output regression.
> The strbuf_addf() was checking buffer length with a result of
> vscnprintf() which cannot be greater than that of strbuf_avail().
>
> Since numa topology and pmu mapping info in header were converted
> to use strbuf, it sometimes caused uninteresting behaviors with the
> broken strbuf.
>
> Fix it by using vsnprintf() which returns desired output string
> length regardless of the available buffer size and grow the buffer
> if needed.
>
> Reported-by: Andrew Jones <drjones@redhat.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/strbuf.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
> index 2eeb51baf077..cfa906882e2c 100644
> --- a/tools/perf/util/strbuf.c
> +++ b/tools/perf/util/strbuf.c
> @@ -90,17 +90,17 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
> if (!strbuf_avail(sb))
> strbuf_grow(sb, 64);
> va_start(ap, fmt);
> - len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
> + len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
> va_end(ap);
> if (len < 0)
> - die("your vscnprintf is broken");
> + die("your vsnprintf is broken");
> if (len > strbuf_avail(sb)) {
> strbuf_grow(sb, len);
> va_start(ap, fmt);
> - len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
> + len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
> va_end(ap);
> if (len > strbuf_avail(sb)) {
> - die("this should not happen, your snprintf is broken");
> + die("this should not happen, your vsnprintf is broken");
> }
> }
> strbuf_setlen(sb, sb->len + len);
> --
> 1.7.9.2
>
Tested-by: Andrew Jones <drjones@redhat.com>
next prev parent reply other threads:[~2012-10-24 7:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-22 13:11 perf: header: Regression Andrew Jones
2012-10-23 2:07 ` Namhyung Kim
2012-10-23 7:27 ` Andrew Jones
2012-10-23 13:44 ` [PATCH 1/2] perf header: Fix numa topology printing Namhyung Kim
2012-10-23 13:44 ` [PATCH 2/2] perf tools: Fix strbuf_addf() when the buffer needs to grow Namhyung Kim
2012-10-24 7:49 ` Andrew Jones [this message]
2012-11-14 6:28 ` [tip:perf/urgent] " tip-bot for Namhyung Kim
2012-10-23 14:12 ` [PATCH 1/2] perf header: Fix numa topology printing Andrew Jones
2012-10-24 7:00 ` Namhyung Kim
2012-10-24 7:49 ` Andrew Jones
2012-10-29 15:17 ` Namhyung Kim
2012-11-14 6:27 ` [tip:perf/urgent] " tip-bot for Namhyung Kim
-- strict thread matches above, loose matches on Subject: below --
2012-10-30 13:02 [GIT PULL 0/2] perf/urgent fixes Arnaldo Carvalho de Melo
2012-10-30 13:02 ` [PATCH 2/2] perf tools: Fix strbuf_addf() when the buffer needs to grow Arnaldo Carvalho de Melo
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=20121024074941.GB2227@turtle.usersys.redhat.com \
--to=drjones@redhat.com \
--cc=acme@ghostprotocols.net \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@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;
as well as URLs for NNTP newsgroup(s).