Re: cvs: php4 /main main.c

From: Date: Fri, 08 Sep 2000 16:02:51 +0000
Subject: Re: cvs: php4 /main main.c
References: 1  Groups: php.cvs php.dev 
Request: Send a blank email to php-dev+get-32688@lists.php.net to get a copy of this message
Best is to create and always use php_snprintf() and php_vsnprintf(). It sucks to stick this checking code in every single place in PHP. Andi At 12:32 PM 9/8/00 +0000, Stanislav Malyshev wrote:
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))
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-cvs-unsubscribe@lists.php.net For additional commands, e-mail: php-cvs-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
--- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.dev (#32688) next »