Skip to content

Commit 7e2fcf9

Browse files
author
Sascha Schumann
committed
Add some checks and avoid passing invalid data to call_user_function_ex.
Fixes some heap corruption and allocation of negative amounts of memory.
1 parent 7e7bbb7 commit 7e2fcf9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

main/output.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size, zend_bool
150150
php_error_docref("ref.outcontrol" TSRMLS_CC, E_ERROR, "Cannot use output buffering in output buffering display handlers");
151151
return FAILURE;
152152
}
153-
if (chunk_size) {
153+
if (chunk_size > 0) {
154154
if (chunk_size==1) {
155155
chunk_size = 4096;
156156
}
@@ -498,10 +498,7 @@ static int php_ob_init(uint initial_size, uint block_size, zval *output_handler,
498498
php_error_docref(NULL TSRMLS_CC, E_ERROR, "No method name given: use ob_start(array($object,'method')) to specify instance $object and the name of a method of class %s to use as output handler", Z_OBJCE_P(output_handler)->name);
499499
result = FAILURE;
500500
} else {
501-
if (output_handler) {
502-
SEPARATE_ZVAL(&output_handler);
503-
}
504-
result = php_ob_init_named(initial_size, block_size, OB_DEFAULT_HANDLER_NAME, output_handler, chunk_size, erase TSRMLS_CC);
501+
result = php_ob_init_named(initial_size, block_size, OB_DEFAULT_HANDLER_NAME, NULL, chunk_size, erase TSRMLS_CC);
505502
}
506503
return result;
507504
}
@@ -719,6 +716,9 @@ PHP_FUNCTION(ob_start)
719716
RETURN_FALSE;
720717
}
721718

719+
if (chunk_size < 0)
720+
chunk_size = 0;
721+
722722
if (php_start_ob_buffer(output_handler, chunk_size, erase TSRMLS_CC)==FAILURE) {
723723
RETURN_FALSE;
724724
}

0 commit comments

Comments
 (0)