From: Peter Seebach <peter.seebach@windriver.com>
To: Anton Blanchard <anton@samba.org>
Cc: <acme@redhat.com>, <paulus@samba.org>, <peterz@infradead.org>,
<mingo@elte.hu>, <dsahern@gmail.com>, <fweisbec@gmail.com>,
<yanmin_zhang@linux.intel.com>, <emunson@mgebm.net>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf: Incorrect use of snprintf results in SEGV
Date: Tue, 6 Mar 2012 18:49:25 -0600 [thread overview]
Message-ID: <20120306184925.56eab8ce@wrlaptop> (raw)
In-Reply-To: <20120307114249.44275ca3@kryten>
On Wed, 7 Mar 2012 11:42:49 +1100
Anton Blanchard <anton@samba.org> wrote:
> This patch fixes repsep_snprintf by clamping the value at size - 1
> which is the maximum snprintf can write before adding the NULL
> terminator.
I would be concerned by this, simply because I at least sometimes
use snprintf-like functions with the understanding that I can check
for overflow by comparing the return value to the size.
... Of course, I think I also make this mistake you describe in other
code, so I'm gonna go look for that.
But simply clamping the value might break code which is relying
on the existing semantics. (And of course, any snprintf-related
crash or misbehavior is likely to happen only when the planets are
aligned just so...)
Possible alternative: Check for a provided size value which is
unreasonably large, and if you get one, assume that it's probably
intended to be negative and refuse to write anything. I don't know
what unreasonably large is, but "large enough that it would have been
negative had it been a signed type" might be a good starting point --
no one should be writing strings that long anyway*.
-s
[*] I am totally ready for someone in twenty years to throw that quote
in my face contemptuously as it shows that I was hopelessly
short-sighted.
--
Listen, get this. Nobody with a good compiler needs to be justified.
next prev parent reply other threads:[~2012-03-07 0:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-07 0:42 [PATCH] perf: Incorrect use of snprintf results in SEGV Anton Blanchard
2012-03-07 0:49 ` Peter Seebach [this message]
2012-03-07 1:09 ` Arnaldo Carvalho de Melo
2012-03-07 1:29 ` Peter Seebach
2012-03-07 18:44 ` Nick Bowler
2012-03-07 20:24 ` Peter Seebach
2012-03-07 20:37 ` Ingo Molnar
2012-03-07 20:59 ` Peter Zijlstra
2012-03-07 21:28 ` Peter Seebach
2012-03-08 7:34 ` Ingo Molnar
2012-03-08 8:51 ` Peter Seebach
2012-03-07 21:19 ` Peter Seebach
2012-03-08 0:58 ` Arnaldo Carvalho de Melo
2012-03-08 7:48 ` Ingo Molnar
2012-03-08 7:52 ` Ingo Molnar
2012-03-09 19:00 ` Peter Seebach
2012-03-14 19:59 ` [tip:perf/urgent] perf tools: " tip-bot for Anton Blanchard
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=20120306184925.56eab8ce@wrlaptop \
--to=peter.seebach@windriver.com \
--cc=acme@redhat.com \
--cc=anton@samba.org \
--cc=dsahern@gmail.com \
--cc=emunson@mgebm.net \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=yanmin_zhang@linux.intel.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox