Skip to content

Commit c15b613

Browse files
committed
Fixed bug #72154 (pcntl_wait/pcntl_waitpid array internal structure overwrite)
1 parent 1a5d58b commit c15b613

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ PHP NEWS
3131
. Fixed bug #71600 (oci_fetch_all segfaults when selecting more than eight
3232
columns). (Tian Yang)
3333

34+
- PCNTL:
35+
. Fixed bug #72154 (pcntl_wait/pcntl_waitpid array internal structure
36+
overwrite). (Laruence)
37+
3438
- Opcache:
3539
. Fixed bug #72014 (Including a file with anonymous classes multiple times
3640
leads to fatal error). (Laruence)

ext/pcntl/pcntl.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,11 @@ PHP_FUNCTION(pcntl_waitpid)
624624
struct rusage rusage;
625625
#endif
626626

627-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/|lz/", &pid, &z_status, &options, &z_rusage) == FAILURE)
627+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/|lz/", &pid, &z_status, &options, &z_rusage) == FAILURE) {
628628
return;
629+
}
629630

630-
convert_to_long_ex(z_status);
631-
632-
status = Z_LVAL_P(z_status);
631+
status = zval_get_long(z_status);
633632

634633
#ifdef HAVE_WAIT4
635634
if (z_rusage) {
@@ -659,7 +658,8 @@ PHP_FUNCTION(pcntl_waitpid)
659658
}
660659
#endif
661660

662-
Z_LVAL_P(z_status) = status;
661+
zval_dtor(z_status);
662+
ZVAL_LONG(z_status, status);
663663

664664
RETURN_LONG((zend_long) child_id);
665665
}
@@ -677,12 +677,11 @@ PHP_FUNCTION(pcntl_wait)
677677
struct rusage rusage;
678678
#endif
679679

680-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/|lz/", &z_status, &options, &z_rusage) == FAILURE)
680+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/|lz/", &z_status, &options, &z_rusage) == FAILURE) {
681681
return;
682+
}
682683

683-
convert_to_long_ex(z_status);
684-
685-
status = Z_LVAL_P(z_status);
684+
status = zval_get_long(z_status);
686685
#ifdef HAVE_WAIT3
687686
if (z_rusage) {
688687
if (Z_TYPE_P(z_rusage) != IS_ARRAY) {
@@ -711,7 +710,9 @@ PHP_FUNCTION(pcntl_wait)
711710
PHP_RUSAGE_TO_ARRAY(rusage, z_rusage);
712711
}
713712
#endif
714-
Z_LVAL_P(z_status) = status;
713+
714+
zval_dtor(z_status);
715+
ZVAL_LONG(z_status, status);
715716

716717
RETURN_LONG((zend_long) child_id);
717718
}

ext/pcntl/tests/bug72154.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #72154 (pcntl_wait/pcntl_waitpid array internal structure overwrite)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("pcntl")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$b = 666;
8+
var_dump($b);
9+
$c = &$b;
10+
$var5 = pcntl_wait($b,0,$c);
11+
unset($b);
12+
13+
$b = 666;
14+
var_dump($b);
15+
$c = &$b;
16+
$var5 = pcntl_waitpid(0,$b,0,$c);
17+
unset($b);
18+
?>
19+
--EXPECT--
20+
int(666)
21+
int(666)

0 commit comments

Comments
 (0)