Commit 8eb73664 authored by Linus Torvalds's avatar Linus Torvalds

Warn loudly if somebody passes a negative value as

the size to "vsnprintf()".

That's a pretty clear case of overflow.
parent 236d2f49
...@@ -254,6 +254,15 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) ...@@ -254,6 +254,15 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* 'z' support added 23/7/1999 S.H. */ /* 'z' support added 23/7/1999 S.H. */
/* 'z' changed to 'Z' --davidm 1/25/99 */ /* 'z' changed to 'Z' --davidm 1/25/99 */
/* Reject out-of-range values early */
if (unlikely((int) size < 0)) {
/* There can be only one.. */
static int warn = 1;
WARN_ON(warn);
warn = 0;
return 0;
}
str = buf; str = buf;
end = buf + size - 1; end = buf + size - 1;
...@@ -498,7 +507,7 @@ EXPORT_SYMBOL(snprintf); ...@@ -498,7 +507,7 @@ EXPORT_SYMBOL(snprintf);
*/ */
int vsprintf(char *buf, const char *fmt, va_list args) int vsprintf(char *buf, const char *fmt, va_list args)
{ {
return vsnprintf(buf, 0xFFFFFFFFUL, fmt, args); return vsnprintf(buf, (~0U)>>1, fmt, args);
} }
EXPORT_SYMBOL(vsprintf); EXPORT_SYMBOL(vsprintf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment