]> granicus.if.org Git - php/commitdiff
Fix DateInterval::format segfault
authorThomas Punt <tpunt@hotmail.co.uk>
Wed, 23 Mar 2016 23:57:50 +0000 (23:57 +0000)
committerAnatol Belski <ab@php.net>
Tue, 5 Apr 2016 09:18:14 +0000 (11:18 +0200)
ext/date/php_date.c
ext/date/tests/bug71889.phpt [new file with mode: 0644]

index 4cb0ec8ff40d4b24529b719ddcc1bba260de9da9..4bb088881e6af5b3f32dfe17da0c6fa45f980e90 100644 (file)
@@ -4359,6 +4359,10 @@ static char *date_interval_format(char *format, int format_len, timelib_rel_time
 
        smart_str_0(&string);
 
+       if (string.c == NULL) {
+               return estrdup("");
+       }
+
        return string.c;
 }
 /* }}} */
diff --git a/ext/date/tests/bug71889.phpt b/ext/date/tests/bug71889.phpt
new file mode 100644 (file)
index 0000000..129930a
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #71889 (DateInterval::format segfault on '%' input)
+--INI--
+date.timezone=US/Eastern
+--FILE--
+<?php
+$di = new DateInterval('P1D');
+var_dump($di->format("%"));
+?>
+--EXPECT--
+string(0) ""