From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Andrew Morton <akpm@linux-foundation.org>,
Jiri Kosina <jkosina@suse.cz>,
Randy Dunlap <rdunlap@infradead.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] lib/vsprintf.c: Improve sanity check in vsnprintf()
Date: Thu, 8 Jan 2015 13:14:45 +0100 [thread overview]
Message-ID: <1420719287-10222-2-git-send-email-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <1420719287-10222-1-git-send-email-linux@rasmusvillemoes.dk>
On 64 bit, size may very well be huge even if bit 31 happens to be
0. Somehow it doesn't feel right that one can pass a 5 GiB buffer but
not a 3 GiB one. So cap at INT_MAX as was probably the intention all
along. This is also the made-up value passed by sprintf and vsprintf.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/vsprintf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 98ad170b10e0..cf12ba86205c 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1727,7 +1727,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
- if (WARN_ON_ONCE((int) size < 0))
+ if (WARN_ON_ONCE(size > INT_MAX))
return 0;
str = buf;
--
2.1.3
next prev parent reply other threads:[~2015-01-08 12:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-08 12:14 [PATCH 1/4] lib/vsprintf.c: Consume 'p' in format_decode Rasmus Villemoes
2015-01-08 12:14 ` Rasmus Villemoes [this message]
2015-01-08 12:14 ` [PATCH 3/4] lib/vsprintf.c: Don't try to fix pointer wrap-around Rasmus Villemoes
2015-01-08 12:14 ` [PATCH 4/4] lib/vsprintf.c: Replace while with do-while in skip_atoi Rasmus Villemoes
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=1420719287-10222-2-git-send-email-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=jkosina@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.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®