[PHP-DEV] CVS update: php3/functions From: sas (php-dev <email protected>)
Date: 04/02/99

Date: Friday April 2, 1999 @ 19:55
Author: sas

Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv2373

Modified Files:
        datetime.c
Log Message:
Fix for #1243

Fix php3_strftime's behaviour to enlarge the buffer infinitely,
if strftime(3) returns 0.

Quote from the Linux man page

       Note that the return value 0 does not necessarily indicate
       an error; for example, in many locales %p yields an empty
       string.

Index: php3/functions/datetime.c
diff -c php3/functions/datetime.c:1.50 php3/functions/datetime.c:1.51
*** php3/functions/datetime.c:1.50 Mon Mar 29 14:54:45 1999
--- php3/functions/datetime.c Fri Apr 2 19:55:40 1999
***************
*** 30,36 ****
   */
  
  
! /* $Id: datetime.c,v 1.50 1999/03/29 19:54:45 cmv Exp $ */
  
  
  #ifdef THREAD_SAFE
--- 30,36 ----
   */
  
  
! /* $Id: datetime.c,v 1.51 1999/04/03 00:55:40 sas Exp $ */
  
  
  #ifdef THREAD_SAFE
***************
*** 499,504 ****
--- 499,505 ----
          char *format,*buf;
          time_t timestamp;
          struct tm *ta;
+ int max_reallocs = 5;
          size_t buf_len=64, real_len;
  
          switch (ARG_COUNT(ht)) {
***************
*** 531,541 ****
          while ((real_len=strftime(buf,buf_len,format,ta))==buf_len || real_len==0) {
                  buf_len *= 2;
                  buf = (char *) erealloc(buf, buf_len);
          }
          
! return_value->value.str.val = (char *) erealloc(buf,real_len+1);
! return_value->value.str.len = real_len;
! return_value->type = IS_STRING;
  }
  /* }}} */
  #endif
--- 532,546 ----
          while ((real_len=strftime(buf,buf_len,format,ta))==buf_len || real_len==0) {
                  buf_len *= 2;
                  buf = (char *) erealloc(buf, buf_len);
+ if(!--max_reallocs) break;
          }
          
! if(real_len && real_len != buf_len) {
! buf = (char *) erealloc(buf,real_len+1);
! RETURN_STRINGL(buf, real_len, 0);
! }
! efree(buf);
! RETURN_FALSE;
  }
  /* }}} */
  #endif

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>