]> granicus.if.org Git - php/commitdiff
MFH: check return value of *time_r() functions for NULL
authorAntony Dovgal <tony2001@php.net>
Thu, 7 Jun 2007 08:44:41 +0000 (08:44 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 7 Jun 2007 08:44:41 +0000 (08:44 +0000)
ext/calendar/cal_unix.c
ext/date/php_date.c
ext/mime_magic/mime_magic.c
main/main.c

index 97c138df2dd8c6d424136659e1dbc38f9067f9fd..4efe16eeeb1e8a26110f0b29edf7cc35c0b6b0fc 100644 (file)
@@ -50,6 +50,10 @@ PHP_FUNCTION(unixtojd)
   }
 
   ta = php_localtime_r(&t, &tmbuf);
+  if (!ta) {
+         RETURN_FALSE;
+  }
+
   jdate = GregorianToSdn(ta->tm_year+1900, ta->tm_mon+1, ta->tm_mday);
   
   RETURN_LONG(jdate);
index 49f76d6a06ecb8762af86f60a320a877118c5875..a1159691d166e9f803b792acc8069759acc737f6 100644 (file)
@@ -578,16 +578,18 @@ static char* guess_timezone(const timelib_tzdb *tzdb TSRMLS_DC)
        {
                struct tm *ta, tmbuf;
                time_t     the_time;
-               char      *tzid;
+               char      *tzid = NULL;
                
                the_time = time(NULL);
                ta = php_localtime_r(&the_time, &tmbuf);
-               tzid = timelib_timezone_id_from_abbr(ta->tm_zone, ta->tm_gmtoff, ta->tm_isdst);
+               if (ta) {
+                       tzid = timelib_timezone_id_from_abbr(ta->tm_zone, ta->tm_gmtoff, ta->tm_isdst);
+               }
                if (! tzid) {
                        tzid = "UTC";
                }
                
-               php_error_docref(NULL TSRMLS_CC, E_STRICT, DATE_TZ_ERRMSG "We selected '%s' for '%s/%.1f/%s' instead", tzid, ta->tm_zone, (float) (ta->tm_gmtoff / 3600), ta->tm_isdst ? "DST" : "no DST");
+               php_error_docref(NULL TSRMLS_CC, E_STRICT, DATE_TZ_ERRMSG "We selected '%s' for '%s/%.1f/%s' instead", tzid, ta ? ta->tm_zone : "Unknown", ta ? (float) (ta->tm_gmtoff / 3600) : 0, ta ? (ta->tm_isdst ? "DST" : "no DST") : "Unknown");
                return tzid;
        }
 #endif
index cb7be9950b51cc0d2181a21c5c1b49f1f412bed7..3828e43d47d08baeb3944faec79983adf35d2918 100644 (file)
@@ -1764,6 +1764,9 @@ static void mprint(union VALUETYPE *p, struct magic *m)
                {
                        char ctimebuf[52];
                        pp = php_ctime_r((time_t *) &p->l, ctimebuf);
+                       if (!pp) {
+                               return;
+                       }
                        if ((rt = strchr(pp, '\n')) != NULL) {
                                *rt = '\0';
                        }
index 2b290efc153c8bfeb9aa022c31f2242cf5ddf78a..1b3fd4ad6e6afa55a4ad8b448b3bd213bd4d19af 100644 (file)
@@ -1021,8 +1021,12 @@ static void php_message_handler_for_zend(long message, void *data)
                                time(&curtime);
                                ta = php_localtime_r(&curtime, &tmbuf);
                                datetime_str = php_asctime_r(ta, asctimebuf);
-                               datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
-                               snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s]  Script:  '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
+                               if (datetime_str) {
+                                       datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
+                                       snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s]  Script:  '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
+                               } else {
+                                       snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[null]  Script:  '%s'\n", SAFE_FILENAME(SG(request_info).path_translated));
+                               }
 #      if defined(PHP_WIN32)
                                OutputDebugString(memory_leak_buf);
 #      else