]> granicus.if.org Git - php/commitdiff
rework fix to php_com_do_invoke_byref,
authorAnatol Belski <ab@php.net>
Tue, 28 Oct 2014 16:23:40 +0000 (17:23 +0100)
committerAnatol Belski <ab@php.net>
Tue, 28 Oct 2014 16:25:09 +0000 (17:25 +0100)
fix crashing function with void arguments

ext/com_dotnet/com_com.c

index 6328a6b090475fef3eecf5bfe8f1c5577383e8cd..e1a9503dffd9401b81d029ce7565ade8a371f83f 100644 (file)
@@ -474,7 +474,7 @@ int php_com_do_invoke_byref(php_com_dotnet_object *obj, zend_internal_function *
        int i, byref_count = 0, j;
 
        /* assumption: that the active function (f) is the function we generated for the engine */
-       if (!f || f->arg_info == NULL) {
+       if (!f) {
                return FAILURE;
        }
        
@@ -496,7 +496,7 @@ int php_com_do_invoke_byref(php_com_dotnet_object *obj, zend_internal_function *
                vargs = (VARIANT*)safe_emalloc(sizeof(VARIANT), nargs, 0);
        }
 
-       if (f) {
+       if (f->arg_info) {
                for (i = 0; i < nargs; i++) {
                        if (f->arg_info[nargs - i - 1].pass_by_reference) {
                                byref_count++;
@@ -551,30 +551,36 @@ int php_com_do_invoke_byref(php_com_dotnet_object *obj, zend_internal_function *
 
        /* release variants */
        if (vargs) {
-               for (i = 0, j = 0; i < nargs; i++) {
-                       /* if this was byref, update the zval */
-                       if (f && f->arg_info[nargs - i - 1].pass_by_reference) {
-                               SEPARATE_ZVAL_IF_NOT_REF(&args[nargs - i - 1]);
-
-                               /* if the variant is pointing at the byref_vals, we need to map
-                                * the pointee value as a zval; otherwise, the value is pointing
-                                * into an existing PHP variant record */
-                               if (V_VT(&vargs[i]) & VT_BYREF) {
-                                       if (vargs[i].byref == &V_UINT(&byref_vals[j])) {
-                                               /* copy that value */
-                                               php_com_zval_from_variant(&args[nargs - i - 1], &byref_vals[j],
+               if (f && f->arg_info) {
+                       for (i = 0, j = 0; i < nargs; i++) {
+                               /* if this was byref, update the zval */
+                               if (f->arg_info[nargs - i - 1].pass_by_reference) {
+                                       SEPARATE_ZVAL_IF_NOT_REF(&args[nargs - i - 1]);
+
+                                       /* if the variant is pointing at the byref_vals, we need to map
+                                        * the pointee value as a zval; otherwise, the value is pointing
+                                        * into an existing PHP variant record */
+                                       if (V_VT(&vargs[i]) & VT_BYREF) {
+                                               if (vargs[i].byref == &V_UINT(&byref_vals[j])) {
+                                                       /* copy that value */
+                                                       php_com_zval_from_variant(&args[nargs - i - 1], &byref_vals[j],
+                                                               obj->code_page TSRMLS_CC);
+                                               }
+                                       } else {
+                                               /* not sure if this can ever happen; the variant we marked as BYREF
+                                                * is no longer BYREF - copy its value */
+                                               php_com_zval_from_variant(&args[nargs - i - 1], &vargs[i],
                                                        obj->code_page TSRMLS_CC);
                                        }
-                               } else {
-                                       /* not sure if this can ever happen; the variant we marked as BYREF
-                                        * is no longer BYREF - copy its value */
-                                       php_com_zval_from_variant(&args[nargs - i - 1], &vargs[i],
-                                               obj->code_page TSRMLS_CC);
+                                       VariantClear(&byref_vals[j]);
+                                       j++;
                                }
-                               VariantClear(&byref_vals[j]);
-                               j++;
-                       }       
-                       VariantClear(&vargs[i]);
+                               VariantClear(&vargs[i]);
+                       }
+               } else {
+                       for (i = 0, j = 0; i < nargs; i++) {
+                               VariantClear(&vargs[i]);
+                       }
                }
                efree(vargs);
        }