[or-cvs] r17600: {tor} Lower sprintf buffer max to ~SSIZE_T_MAX from SIZE_T_CEILING (tor/trunk/src/common)

nickm at seul.org nickm at seul.org
Thu Dec 11 21:11:22 UTC 2008


Author: nickm
Date: 2008-12-11 16:11:22 -0500 (Thu, 11 Dec 2008)
New Revision: 17600

Modified:
   tor/trunk/src/common/compat.c
Log:
Lower sprintf buffer max to ~SSIZE_T_MAX from SIZE_T_CEILING, since we need to compare it to a signed int.

Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c	2008-12-11 21:11:19 UTC (rev 17599)
+++ tor/trunk/src/common/compat.c	2008-12-11 21:11:22 UTC (rev 17600)
@@ -303,7 +303,7 @@
   int r;
   if (size == 0)
     return -1; /* no place for the NUL */
-  if (size > SIZE_T_CEILING)
+  if (size > SSIZE_T_MAX-16)
     return -1;
 #ifdef MS_WINDOWS
   r = _vsnprintf(str, size, format, args);
@@ -311,7 +311,7 @@
   r = vsnprintf(str, size, format, args);
 #endif
   str[size-1] = '\0';
-  if (r < 0 || ((size_t)r) >= size)
+  if (r < 0 || r >= (ssize_t)size)
     return -1;
   return r;
 }



More information about the tor-commits mailing list