]> granicus.if.org Git - php/commitdiff
Fix #78694: Appending to a variant array causes segfault
authorChristoph M. Becker <cmbecker69@gmx.de>
Sat, 19 Oct 2019 09:41:28 +0000 (11:41 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sat, 19 Oct 2019 09:47:00 +0000 (11:47 +0200)
`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.

NEWS
ext/com_dotnet/com_handlers.c
ext/com_dotnet/tests/bug78694.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 2028649849bfbcf55d9504560e30e640b73bf1c5..d63dd99d6edd225c191ae4ef108a83438fccadb1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ PHP                                                                        NEWS
   . Fixed bug #78656 (Parse errors classified as highest log-level). (Erik
     Lundin)
 
+- COM:
+  . Fixed bug #78694 (Appending to a variant array causes segfault). (cmb)
+
 - Date:
   . Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin)
 
index 1fc6c04c9a062c90a18b99d8c1153be05cffe538..e7b0aa4bf45e60639d655e31652aea96a63e857d 100644 (file)
@@ -127,6 +127,11 @@ static void com_write_dimension(zval *object, zval *offset, zval *value)
 
        obj = CDNO_FETCH(object);
 
+       if (offset == NULL) {
+               php_com_throw_exception(DISP_E_BADINDEX, "appending to variants is not supported");
+               return;
+       }
+
        if (V_VT(&obj->v) == VT_DISPATCH) {
                ZVAL_COPY_VALUE(&args[0], offset);
                ZVAL_COPY_VALUE(&args[1], value);
diff --git a/ext/com_dotnet/tests/bug78694.phpt b/ext/com_dotnet/tests/bug78694.phpt
new file mode 100644 (file)
index 0000000..adf0c82
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Bug #78694 (Appending to a variant array causes segfault)
+--SKIPIF--
+<?php
+if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
+?>
+--FILE--
+<?php
+foreach ([new com('WScript.Shell'), new variant([])] as $var) {
+    try {
+        $var[] = 42;
+    } catch (com_exception $ex) {
+        var_dump($ex->getMessage());
+    }
+}
+?>
+--EXPECT--
+string(38) "appending to variants is not supported"
+string(38) "appending to variants is not supported"