Skip to content

Commit 54a1c7b

Browse files
committed
Fix use-after-free in php_date.c
1 parent dd9ace3 commit 54a1c7b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ext/date/php_date.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,8 +2263,9 @@ PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object) /* {{{ */
22632263

22642264
/* Helper function used to store the latest found warnings and errors while
22652265
* parsing, from either strtotime or parse_from_format. */
2266-
static void update_errors_warnings(timelib_error_container *last_errors) /* {{{ */
2266+
static void update_errors_warnings(timelib_error_container **last_errors_ptr) /* {{{ */
22672267
{
2268+
timelib_error_container *last_errors = *last_errors_ptr;
22682269
if (DATEG(last_errors)) {
22692270
timelib_error_container_dtor(DATEG(last_errors));
22702271
DATEG(last_errors) = NULL;
@@ -2273,6 +2274,7 @@ static void update_errors_warnings(timelib_error_container *last_errors) /* {{{
22732274
DATEG(last_errors) = last_errors;
22742275
} else {
22752276
timelib_error_container_dtor(last_errors);
2277+
*last_errors_ptr = NULL;
22762278
}
22772279
} /* }}} */
22782280

@@ -2324,7 +2326,7 @@ PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, siz
23242326
}
23252327

23262328
/* update last errors and warnings */
2327-
update_errors_warnings(err);
2329+
update_errors_warnings(&err);
23282330

23292331
/* If called from a constructor throw an exception */
23302332
if ((flags & PHP_DATE_INIT_CTOR) && err && err->error_count) {
@@ -3002,7 +3004,7 @@ static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{
30023004
tmp_time = timelib_strtotime(modify, modify_len, &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
30033005

30043006
/* update last errors and warnings */
3005-
update_errors_warnings(err);
3007+
update_errors_warnings(&err);
30063008
if (err && err->error_count) {
30073009
/* spit out the first library error message, at least */
30083010
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", modify,

0 commit comments

Comments
 (0)