]> granicus.if.org Git - php/commitdiff
Avoid unitialized variable warning in soap
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 11:18:23 +0000 (13:18 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 13:12:39 +0000 (15:12 +0200)
Extract envelope fetch into separate function, so the control
flow becomes more obvious.

ext/soap/soap.c

index 0209125bbca43b7f43ea97001871b6c9fdba29e9..3f86b6200b47ecde26e6fd9c7a219f3794a3051f 100644 (file)
@@ -2079,7 +2079,7 @@ static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeade
 }
 /* }}} */
 
-static void soap_server_fault(char* code, char* string, char *actor, zval* details, char* name) /* {{{ */
+static ZEND_NORETURN void soap_server_fault(char* code, char* string, char *actor, zval* details, char* name) /* {{{ */
 {
        zval ret;
 
@@ -3400,37 +3400,43 @@ static sdlFunctionPtr find_function(sdlPtr sdl, xmlNodePtr func, zval* function_
 }
 /* }}} */
 
-static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, char* actor, zval *function_name, int *num_params, zval **parameters, int *version, soapHeader **headers) /* {{{ */
-{
-       char* envelope_ns = NULL;
-       xmlNodePtr trav,env,head,body,func;
-       xmlAttrPtr attr;
-       sdlFunctionPtr function;
-
-       encode_reset_ns();
-
-       /* Get <Envelope> element */
-       env = NULL;
-       trav = request->children;
+static xmlNodePtr get_envelope(xmlNodePtr trav, int *version, char **envelope_ns) {
        while (trav != NULL) {
                if (trav->type == XML_ELEMENT_NODE) {
-                       if (env == NULL && node_is_equal_ex(trav,"Envelope",SOAP_1_1_ENV_NAMESPACE)) {
-                               env = trav;
+                       if (node_is_equal_ex(trav,"Envelope",SOAP_1_1_ENV_NAMESPACE)) {
                                *version = SOAP_1_1;
-                               envelope_ns = SOAP_1_1_ENV_NAMESPACE;
+                               *envelope_ns = SOAP_1_1_ENV_NAMESPACE;
                                SOAP_GLOBAL(soap_version) = SOAP_1_1;
-                       } else if (env == NULL && node_is_equal_ex(trav,"Envelope",SOAP_1_2_ENV_NAMESPACE)) {
-                               env = trav;
+                               return trav;
+                       }
+
+                       if (node_is_equal_ex(trav,"Envelope",SOAP_1_2_ENV_NAMESPACE)) {
                                *version = SOAP_1_2;
-                               envelope_ns = SOAP_1_2_ENV_NAMESPACE;
+                               *envelope_ns = SOAP_1_2_ENV_NAMESPACE;
                                SOAP_GLOBAL(soap_version) = SOAP_1_2;
-                       } else {
-                               soap_server_fault("VersionMismatch", "Wrong Version", NULL, NULL, NULL);
+                               return trav;
                        }
+
+                       soap_server_fault("VersionMismatch", "Wrong Version", NULL, NULL, NULL);
                }
                trav = trav->next;
        }
-       if (env == NULL) {
+
+       return NULL;
+}
+
+static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, char* actor, zval *function_name, int *num_params, zval **parameters, int *version, soapHeader **headers) /* {{{ */
+{
+       char* envelope_ns = NULL;
+       xmlNodePtr trav,env,head,body,func;
+       xmlAttrPtr attr;
+       sdlFunctionPtr function;
+
+       encode_reset_ns();
+
+       /* Get <Envelope> element */
+       env = get_envelope(request->children, version, &envelope_ns);
+       if (!env) {
                soap_server_fault("Client", "looks like we got XML without \"Envelope\" element", NULL, NULL, NULL);
        }