Skip to content

Commit 45a7723

Browse files
committed
Fix #78694: Appending to a variant array causes segfault
`write_dimension` object handlers have to be able to handle `NULL` `offset`s; for now we simply throw an exception instead of following the `NULL` pointer.
1 parent d2cde0b commit 45a7723

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug #78656 (Parse errors classified as highest log-level). (Erik
77
Lundin)
88

9+
- COM:
10+
. Fixed bug #78694 (Appending to a variant array causes segfault). (cmb)
11+
912
- Date:
1013
. Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin)
1114

ext/com_dotnet/com_handlers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ static void com_write_dimension(zval *object, zval *offset, zval *value)
127127

128128
obj = CDNO_FETCH(object);
129129

130+
if (offset == NULL) {
131+
php_com_throw_exception(DISP_E_BADINDEX, "appending to variants is not supported");
132+
return;
133+
}
134+
130135
if (V_VT(&obj->v) == VT_DISPATCH) {
131136
ZVAL_COPY_VALUE(&args[0], offset);
132137
ZVAL_COPY_VALUE(&args[1], value);

ext/com_dotnet/tests/bug78694.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #78694 (Appending to a variant array causes segfault)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
foreach ([new com('WScript.Shell'), new variant([])] as $var) {
10+
try {
11+
$var[] = 42;
12+
} catch (com_exception $ex) {
13+
var_dump($ex->getMessage());
14+
}
15+
}
16+
?>
17+
--EXPECT--
18+
string(38) "appending to variants is not supported"
19+
string(38) "appending to variants is not supported"

0 commit comments

Comments
 (0)