Lower sprintf buffer max to ~SSIZE_T_MAX from SIZE_T_CEILING, since we need to compare it to a signed int.

svn:r17600
This commit is contained in:
Nick Mathewson 2008-12-11 21:11:22 +00:00
parent b20694758e
commit 98066d62bc

View File

@ -303,7 +303,7 @@ tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
int r; int r;
if (size == 0) if (size == 0)
return -1; /* no place for the NUL */ return -1; /* no place for the NUL */
if (size > SIZE_T_CEILING) if (size > SSIZE_T_MAX-16)
return -1; return -1;
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
r = _vsnprintf(str, size, format, args); r = _vsnprintf(str, size, format, args);
@ -311,7 +311,7 @@ tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
r = vsnprintf(str, size, format, args); r = vsnprintf(str, size, format, args);
#endif #endif
str[size-1] = '\0'; str[size-1] = '\0';
if (r < 0 || ((size_t)r) >= size) if (r < 0 || r >= (ssize_t)size)
return -1; return -1;
return r; return r;
} }