Skip to content

Commit a8daef5

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
2 parents 251e948 + 461e140 commit a8daef5

File tree

6 files changed

+92
-18
lines changed

6 files changed

+92
-18
lines changed

Zend/tests/bug77660.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #77660 (Segmentation fault on break 2147483648)
3+
--SKIPIF--
4+
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
5+
--FILE--
6+
<?php
7+
for(;;) break 2147483648;
8+
?>
9+
--EXPECTF--
10+
Fatal error: Cannot 'break' 2147483648 levels in %sbug77660.php on line %d
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Calling exception getters when properties hold references
3+
--FILE--
4+
<?php
5+
6+
class MyException extends Exception {
7+
public function __construct(&$refMsg, &$refCode, &$refFile, &$refLine) {
8+
$this->message =& $refMsg;
9+
$this->code =& $refCode;
10+
$this->file =& $refFile;
11+
$this->line =& $refLine;
12+
}
13+
}
14+
15+
$refMsg = "foo";
16+
$refCode = 0;
17+
$refFile = "foobar";
18+
$refLine = 42;
19+
$ex = new MyException($refMsg, $refCode, $refFile, $refLine);
20+
var_dump($ex->getMessage());
21+
var_dump($ex->getCode());
22+
var_dump($ex->getFile());
23+
var_dump($ex->getLine());
24+
25+
?>
26+
--EXPECT--
27+
string(3) "foo"
28+
int(0)
29+
string(6) "foobar"
30+
int(42)

Zend/zend_compile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4303,7 +4303,7 @@ void zend_compile_break_continue(zend_ast *ast) /* {{{ */
43034303
zend_ast *depth_ast = ast->child[0];
43044304

43054305
zend_op *opline;
4306-
int depth;
4306+
zend_long depth;
43074307

43084308
ZEND_ASSERT(ast->kind == ZEND_AST_BREAK || ast->kind == ZEND_AST_CONTINUE);
43094309

@@ -4330,7 +4330,7 @@ void zend_compile_break_continue(zend_ast *ast) /* {{{ */
43304330
ast->kind == ZEND_AST_BREAK ? "break" : "continue");
43314331
} else {
43324332
if (!zend_handle_loops_and_finally_ex(depth, NULL)) {
4333-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot '%s' %d level%s",
4333+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot '%s' " ZEND_LONG_FMT " level%s",
43344334
ast->kind == ZEND_AST_BREAK ? "break" : "continue",
43354335
depth, depth == 1 ? "" : "s");
43364336
}
@@ -4347,12 +4347,12 @@ void zend_compile_break_continue(zend_ast *ast) /* {{{ */
43474347
if (depth == 1) {
43484348
zend_error(E_WARNING,
43494349
"\"continue\" targeting switch is equivalent to \"break\". " \
4350-
"Did you mean to use \"continue %d\"?",
4350+
"Did you mean to use \"continue " ZEND_LONG_FMT "\"?",
43514351
depth + 1);
43524352
} else {
43534353
zend_error(E_WARNING,
4354-
"\"continue %d\" targeting switch is equivalent to \"break %d\". " \
4355-
"Did you mean to use \"continue %d\"?",
4354+
"\"continue " ZEND_LONG_FMT "\" targeting switch is equivalent to \"break " ZEND_LONG_FMT "\". " \
4355+
"Did you mean to use \"continue " ZEND_LONG_FMT "\"?",
43564356
depth, depth, depth + 1);
43574357
}
43584358
}

Zend/zend_exceptions.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -400,71 +400,83 @@ ZEND_METHOD(error_exception, __construct)
400400
Get the file in which the exception occurred */
401401
ZEND_METHOD(exception, getFile)
402402
{
403-
zval rv;
403+
zval *prop, rv;
404404

405405
DEFAULT_0_PARAMS;
406406

407-
ZVAL_COPY(return_value, GET_PROPERTY(ZEND_THIS, ZEND_STR_FILE));
407+
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_FILE);
408+
ZVAL_DEREF(prop);
409+
ZVAL_COPY(return_value, prop);
408410
}
409411
/* }}} */
410412

411413
/* {{{ proto int Exception|Error::getLine()
412414
Get the line in which the exception occurred */
413415
ZEND_METHOD(exception, getLine)
414416
{
415-
zval rv;
417+
zval *prop, rv;
416418

417419
DEFAULT_0_PARAMS;
418420

419-
ZVAL_COPY(return_value, GET_PROPERTY(ZEND_THIS, ZEND_STR_LINE));
421+
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_LINE);
422+
ZVAL_DEREF(prop);
423+
ZVAL_COPY(return_value, prop);
420424
}
421425
/* }}} */
422426

423427
/* {{{ proto string Exception|Error::getMessage()
424428
Get the exception message */
425429
ZEND_METHOD(exception, getMessage)
426430
{
427-
zval rv;
431+
zval *prop, rv;
428432

429433
DEFAULT_0_PARAMS;
430434

431-
ZVAL_COPY(return_value, GET_PROPERTY(ZEND_THIS, ZEND_STR_MESSAGE));
435+
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_MESSAGE);
436+
ZVAL_DEREF(prop);
437+
ZVAL_COPY(return_value, prop);
432438
}
433439
/* }}} */
434440

435441
/* {{{ proto int Exception|Error::getCode()
436442
Get the exception code */
437443
ZEND_METHOD(exception, getCode)
438444
{
439-
zval rv;
445+
zval *prop, rv;
440446

441447
DEFAULT_0_PARAMS;
442448

443-
ZVAL_COPY(return_value, GET_PROPERTY(ZEND_THIS, ZEND_STR_CODE));
449+
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_CODE);
450+
ZVAL_DEREF(prop);
451+
ZVAL_COPY(return_value, prop);
444452
}
445453
/* }}} */
446454

447455
/* {{{ proto array Exception|Error::getTrace()
448456
Get the stack trace for the location in which the exception occurred */
449457
ZEND_METHOD(exception, getTrace)
450458
{
451-
zval rv;
459+
zval *prop, rv;
452460

453461
DEFAULT_0_PARAMS;
454462

455-
ZVAL_COPY(return_value, GET_PROPERTY(ZEND_THIS, ZEND_STR_TRACE));
463+
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_TRACE);
464+
ZVAL_DEREF(prop);
465+
ZVAL_COPY(return_value, prop);
456466
}
457467
/* }}} */
458468

459469
/* {{{ proto int ErrorException::getSeverity()
460470
Get the exception severity */
461471
ZEND_METHOD(error_exception, getSeverity)
462472
{
463-
zval rv;
473+
zval *prop, rv;
464474

465475
DEFAULT_0_PARAMS;
466476

467-
ZVAL_COPY(return_value, GET_PROPERTY(ZEND_THIS, ZEND_STR_SEVERITY));
477+
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_SEVERITY);
478+
ZVAL_DEREF(prop);
479+
ZVAL_COPY(return_value, prop);
468480
}
469481
/* }}} */
470482

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
BUG #77664 (Segmentation fault when using undefined constant in custom wrapper)
3+
--FILE--
4+
<?php
5+
class ErrorWrapper {
6+
public $context;
7+
public $var = self::INVALID;
8+
}
9+
stream_wrapper_register('error',ErrorWrapper::class);
10+
file_get_contents('error://test');
11+
?>
12+
--EXPECTF--
13+
Warning: file_get_contents(error://test): failed to open stream: operation failed in %sbug77664.php on line %d
14+
15+
Fatal error: Uncaught Error: Undefined class constant 'self::INVALID' in %sbug77664.php:%d
16+
Stack trace:
17+
#0 %sbug77664.php(%d): file_get_contents('error://test')
18+
#1 {main}
19+
thrown in %sbug77664.php on line %d

main/streams/userspace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,10 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php
287287
}
288288

289289
/* create an instance of our class */
290-
object_init_ex(object, uwrap->ce);
290+
if (object_init_ex(object, uwrap->ce) == FAILURE) {
291+
ZVAL_UNDEF(object);
292+
return;
293+
}
291294

292295
if (context) {
293296
add_property_resource(object, "context", context->res);

0 commit comments

Comments
 (0)