diff --git a/ext/date/php_date.c b/ext/date/php_date.c index e06ace7f8b81..8f38f24aeb4b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4309,7 +4309,7 @@ static char *date_interval_format(char *format, int format_len, timelib_rel_time char buffer[33]; if (!format_len) { - return estrdup(""); + return STR_EMPTY_ALLOC(); } for (i = 0; i < format_len; i++) { @@ -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 STR_EMPTY_ALLOC(); + } + return string.c; } /* }}} */ diff --git a/ext/date/tests/bug71889.phpt b/ext/date/tests/bug71889.phpt new file mode 100644 index 000000000000..129930a1fc5f --- /dev/null +++ b/ext/date/tests/bug71889.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #71889 (DateInterval::format segfault on '%' input) +--INI-- +date.timezone=US/Eastern +--FILE-- +format("%")); +?> +--EXPECT-- +string(0) ""