cvs: php4 /main main.c
| From: | Stanislav Malyshev | Date: | Fri, 08 Sep 2000 12:32:29 +0000 |
| Subject: | cvs: php4 /main main.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1633@lists.php.net to get a copy of this message | ||
stas Fri Sep 8 05:32:29 2000 EDT
Modified files:
/php4/main main.c
Log:
Fix crash on very long error messages
Manual for snprintf says:
If the output was truncated, the return value is -1, oth-
erwise it is the number of characters stored, not includ-
ing the terminating null.
And that's a blatant lie - in reality, libc 2.1 always returns number of
characters that _would be_ stored. I hate those libc bugs. Now we should go
and check every place we trusted snprintf return value.
Index: php4/main/main.c
diff -u php4/main/main.c:1.314 php4/main/main.c:1.315
--- php4/main/main.c:1.314 Fri Sep 8 05:07:21 2000
+++ php4/main/main.c Fri Sep 8 05:32:29 2000
@@ -19,7 +19,7 @@
*/
-/* $Id: main.c,v 1.314 2000/09/08 12:07:21 stas Exp $ */
+/* $Id: main.c,v 1.315 2000/09/08 12:32:29 stas Exp $ */
#include <stdio.h>
@@ -334,6 +334,9 @@
buffer_len = vsnprintf(buffer, sizeof(buffer)-1, format, args);
buffer[sizeof(buffer)-1]=0;
+ if(buffer_len > sizeof(buffer) - 1 || buffer_len < 0) {
+ buffer_len = sizeof(buffer) - 1;
+ }
/* display/log the error if necessary */
if ((EG(error_reporting) & type || (type & E_CORE))