From:             adriano at guiadohardware dot net
Operating system: AMD64 Gentoo Hardened, glibc 2.3
PHP version:      5.2.9
PHP Bug Type:     Date/time related
Bug description:  gettimeofday raise SEGFAULT

Description:
------------
Hi,

On my server the second argument on gettimeofday raise SEGFAULT. I can't
reproduce this error using another system lib version of another server. As
manpage of gettimeofday said: "If tzp is not a null pointer, the behavior
is unspecified. " (http://linux.die.net/man/3/gettimeofday). This old
timezone is no longer used and must be kept outside of kernel. After the
patch below this worked.


--- php-5.2.9/ext/standard/microtime.c  2009-05-20 12:07:39.000000000
-0300
+++ php-5.2.9/ext/standard/microtime.c  2009-05-20 12:08:33.000000000
-0300
@@ -54,13 +54,12 @@
 {
        zend_bool get_as_float = 0;
        struct timeval tp = {0};
-       struct timezone tz = {0};
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b",
&get_as_float) == FAILURE) {
                return;
        }
 
-       if (gettimeofday(&tp, &tz)) {
+       if (gettimeofday(&tp, NULL)) {
                RETURN_FALSE;
        }
 


Reproduce code:
---------------
crash.php
<?
print_r(gettimeofday());
?>
gettimeofday.c
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int main(void) {
  char buffer[30]; struct timeval tv = {0}; struct timezone tz = {0};
time_t curtime;
  gettimeofday(&tv, &tz); 
  curtime=tv.tv_sec;
  strftime(buffer,30,"%m-%d-%Y  %T.",localtime(&curtime));
  printf("%s%ld\n",buffer,tv.tv_usec);
  return 0;
}

Expected result:
----------------
~ # gcc -Wall -O0 gettimeofday.c -o gettimeofday
~ # ./gettimeofday 
Segmentation fault
~ # ./crash.php
Segmentation fault



-- 
Edit bug report at http://bugs.php.net/?id=48346&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48346&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48346&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48346&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48346&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48346&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48346&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48346&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48346&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48346&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48346&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48346&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48346&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48346&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48346&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48346&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48346&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48346&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48346&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48346&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48346&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48346&r=mysqlcfg

Reply via email to