Skip to content

Commit

Permalink
Fixed bug #80290
Browse files Browse the repository at this point in the history
Dropping the dtor arg args[3] rather than using STR_COPY: Since
PHP 8, we no longer support separation in call_user_function(),
so we also don't need to worry about things like arguments being
replaced with references.
  • Loading branch information
nikic committed Oct 30, 2020
1 parent b133183 commit 3bd3651
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ PHP NEWS
- Standard:
. Don't force rebuild of symbol table, when populating $http_response_header
variable by the HTTP stream wrapper. (Dmitry)
. Fixed bug #80290 (Double free when ASSERT_CALLBACK is used with a dynamic
message). (Nikita)

29 Oct 2020, PHP 8.0.0RC3

Expand Down
6 changes: 1 addition & 5 deletions ext/standard/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,11 @@ PHP_FUNCTION(assert)
if (description_str) {
ZVAL_STR(&args[3], description_str);
call_user_function(NULL, NULL, &ASSERTG(callback), &retval, 4, args);
zval_ptr_dtor(&(args[3]));
zval_ptr_dtor(&(args[2]));
zval_ptr_dtor(&(args[0]));
} else {
call_user_function(NULL, NULL, &ASSERTG(callback), &retval, 3, args);
zval_ptr_dtor(&(args[2]));
zval_ptr_dtor(&(args[0]));
}

zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&retval);
}

Expand Down
21 changes: 21 additions & 0 deletions ext/standard/tests/assert/bug80290.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #80290: Double free when ASSERT_CALLBACK is used with a dynamic message
--FILE--
<?php

assert_options(ASSERT_CALLBACK, function($file, $line, $unused, $message) {
var_dump($message);
});

$x = 'x';
assert(false, 'Dynamic message: ' . $x);

?>
--EXPECTF--
string(18) "Dynamic message: x"

Fatal error: Uncaught AssertionError: Dynamic message: x in %s:%d
Stack trace:
#0 %s(%d): assert(false, 'Dynamic message...')
#1 {main}
thrown in %s on line %d

0 comments on commit 3bd3651

Please sign in to comment.