@@ -70,12 +70,17 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
7070 return ;
7171 }
7272
73+ if (UNEXPECTED (nargs == 0 )) {
74+ zend_throw_error (NULL , "Function name must be passed as the first argument" );
75+ return ;
76+ }
77+
7378 fci .param_count = nargs - 1 ;
7479 if (fci .param_count > 0 ) {
7580 fci .params = safe_emalloc (fci .param_count , sizeof (zval ), 0 );
7681 }
7782 /* Reverse order to pop values off ctxt stack */
78- for (i = nargs - 2 ; i >= 0 ; i -- ) {
83+ for (i = fci . param_count - 1 ; i >= 0 ; i -- ) {
7984 obj = valuePop (ctxt );
8085 switch (obj -> type ) {
8186 case XPATH_STRING :
@@ -128,11 +133,12 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
128133
129134 fci .size = sizeof (fci );
130135
136+ /* Last element of the stack is the function name */
131137 obj = valuePop (ctxt );
132138 if (obj -> stringval == NULL ) {
133139 zend_type_error ("Handler name must be a string" );
134140 xmlXPathFreeObject (obj );
135- goto cleanup ;
141+ goto cleanup_no_callable ;
136142 }
137143 ZVAL_STRING (& fci .function_name , (char * ) obj -> stringval );
138144 xmlXPathFreeObject (obj );
@@ -177,6 +183,7 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
177183cleanup :
178184 zend_string_release_ex (callable , 0 );
179185 zval_ptr_dtor_nogc (& fci .function_name );
186+ cleanup_no_callable :
180187 if (fci .param_count > 0 ) {
181188 for (i = 0 ; i < nargs - 1 ; i ++ ) {
182189 zval_ptr_dtor (& fci .params [i ]);
0 commit comments