From 10a9a09f886d7fe3b97268281c925f4b46f477dd Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 16 Oct 2024 15:14:46 +0100 Subject: [PATCH 1/8] ext/soap: Reduce scope of variable --- ext/soap/php_sdl.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index a44fc16f9716a..bd239b18bfa4a 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -299,7 +299,6 @@ static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) sdlPtr tmpsdl = ctx->sdl; xmlDocPtr wsdl; xmlNodePtr root, definitions, trav; - xmlAttrPtr targetNamespace; if (zend_hash_str_exists(&ctx->docs, struri, strlen(struri))) { return; @@ -335,7 +334,7 @@ static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) } if (!include) { - targetNamespace = get_attribute(definitions->properties, "targetNamespace"); + xmlAttrPtr targetNamespace = get_attribute(definitions->properties, "targetNamespace"); if (targetNamespace) { tmpsdl->target_ns = estrdup((char*)targetNamespace->children->content); } @@ -528,13 +527,13 @@ static sdlSoapBindingFunctionHeaderPtr wsdl_soap_binding_header(sdlCtx* ctx, xml static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap_namespace, sdlSoapBindingFunctionBody *binding, HashTable* params) { - xmlNodePtr body, trav; + xmlNodePtr trav; xmlAttrPtr tmp; trav = node->children; while (trav != NULL) { if (node_is_equal_ex(trav, "body", wsdl_soap_namespace)) { - body = trav; + xmlNodePtr body = trav; tmp = get_attribute(body->properties, "use"); if (tmp && !strncmp((char*)tmp->children->content, "literal", sizeof("literal"))) { @@ -628,7 +627,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) { - xmlNodePtr trav, part, message = NULL, tmp; + xmlNodePtr trav, message = NULL, tmp; HashTable* parameters = NULL; char *ctype; @@ -648,7 +647,7 @@ static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) trav = message->children; while (trav != NULL) { - xmlAttrPtr element, type, name; + xmlAttrPtr type, name; sdlParamPtr param; if (trav->ns != NULL && strcmp((char*)trav->ns->href, WSDL_NAMESPACE) != 0) { @@ -661,7 +660,7 @@ static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) if (!node_is_equal(trav,"part")) { soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav->name)); } - part = trav; + xmlNodePtr part = trav; param = emalloc(sizeof(sdlParam)); memset(param,0,sizeof(sdlParam)); param->order = 0; @@ -677,7 +676,7 @@ static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) if (type != NULL) { param->encode = get_encoder_from_prefix(ctx->sdl, part, type->children->content); } else { - element = get_attribute(part->properties, "element"); + xmlAttrPtr element = get_attribute(part->properties, "element"); if (element != NULL) { param->element = get_element(ctx->sdl, part, element->children->content); if (param->element) { @@ -696,7 +695,6 @@ static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) static sdlPtr load_wsdl(zval *this_ptr, char *struri) { sdlCtx ctx; - size_t i,n; memset(&ctx,0,sizeof(ctx)); ctx.sdl = emalloc(sizeof(sdl)); @@ -714,10 +712,10 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) load_wsdl_ex(this_ptr, struri, &ctx, 0); schema_pass2(&ctx); - n = zend_hash_num_elements(&ctx.services); + uint32_t n = zend_hash_num_elements(&ctx.services); if (n > 0) { zend_hash_internal_pointer_reset(&ctx.services); - for (i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { xmlNodePtr service, tmp; xmlNodePtr trav, port; int has_soap_port = 0; From 51867879ae20e982e19dbd306181fd9e5f953987 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 16 Oct 2024 15:15:03 +0100 Subject: [PATCH 2/8] ext/soap: Replace memset with 0 initialization --- ext/soap/php_sdl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index bd239b18bfa4a..2feed2a3390fc 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -694,9 +694,8 @@ static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) static sdlPtr load_wsdl(zval *this_ptr, char *struri) { - sdlCtx ctx; + sdlCtx ctx = {0}; - memset(&ctx,0,sizeof(ctx)); ctx.sdl = emalloc(sizeof(sdl)); memset(ctx.sdl, 0, sizeof(sdl)); ctx.sdl->source = estrdup(struri); From 1b5e16e78d7b6cad688f2b8a258be37c80467556 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 16 Oct 2024 15:23:34 +0100 Subject: [PATCH 3/8] ext/soap: Use bool instead of int --- ext/soap/php_sdl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 2feed2a3390fc..07536bc13bffd 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -294,7 +294,7 @@ void sdl_restore_uri_credentials(sdlCtx *ctx) #define SAFE_STR(a) ((a)?((const char *)a):"") -static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) +static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, bool include) { sdlPtr tmpsdl = ctx->sdl; xmlDocPtr wsdl; @@ -363,7 +363,7 @@ static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) xmlAttrPtr tmp = get_attribute(trav->properties, "location"); if (tmp) { xmlChar *uri = schema_location_construct_uri(tmp); - load_wsdl_ex(this_ptr, (char*)uri, ctx, 1); + load_wsdl_ex(this_ptr, (char*)uri, ctx, true); xmlFree(uri); } @@ -556,7 +556,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap zend_hash_init(&ht, 0, NULL, delete_parameter, 0); while (*parts) { sdlParamPtr param; - int found = 0; + bool found = false; char *end; while (*parts == ' ') ++parts; @@ -571,7 +571,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap *x_param = *param; param->paramName = NULL; zend_hash_next_index_insert_ptr(&ht, x_param); - found = 1; + found = true; break; } } ZEND_HASH_FOREACH_END(); @@ -708,7 +708,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) zend_hash_init(&ctx.services, 0, NULL, NULL, 0); zend_try { - load_wsdl_ex(this_ptr, struri, &ctx, 0); + load_wsdl_ex(this_ptr, struri, &ctx, false); schema_pass2(&ctx); uint32_t n = zend_hash_num_elements(&ctx.services); @@ -717,7 +717,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) for (uint32_t i = 0; i < n; i++) { xmlNodePtr service, tmp; xmlNodePtr trav, port; - int has_soap_port = 0; + bool has_soap_port = false; service = tmp = zend_hash_get_current_data_ptr(&ctx.services); @@ -787,7 +787,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) soap_error0(E_ERROR, "Parsing WSDL: No address associated with "); } } - has_soap_port = 1; + has_soap_port = true; location = get_attribute(address->properties, "location"); if (!location) { From b545c951ce188819948070ed11b1f617e4023f62 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 16 Oct 2024 16:04:45 +0100 Subject: [PATCH 4/8] ext/soap: Eliminate some variable shadowing --- ext/soap/php_sdl.c | 105 ++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 07536bc13bffd..4466b539d1e14 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -810,7 +810,6 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) if (tmpbinding->bindingType == BINDING_SOAP) { sdlSoapBindingPtr soapBinding; xmlNodePtr soapBindingNode; - xmlAttrPtr tmp; soapBinding = emalloc(sizeof(sdlSoapBinding)); memset(soapBinding, 0, sizeof(sdlSoapBinding)); @@ -818,14 +817,14 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) soapBindingNode = get_node_ex(binding->children, "binding", wsdl_soap_namespace); if (soapBindingNode) { - tmp = get_attribute(soapBindingNode->properties, "style"); - if (tmp && !strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) { + xmlAttrPtr styleAttribute = get_attribute(soapBindingNode->properties, "style"); + if (styleAttribute && !strncmp((char*)styleAttribute->children->content, "rpc", sizeof("rpc"))) { soapBinding->style = SOAP_RPC; } - tmp = get_attribute(soapBindingNode->properties, "transport"); - if (tmp) { - if (strncmp((char*)tmp->children->content, WSDL_HTTP_TRANSPORT, sizeof(WSDL_HTTP_TRANSPORT)) == 0) { + xmlAttrPtr transportAttribute = get_attribute(soapBindingNode->properties, "transport"); + if (transportAttribute) { + if (strncmp((char*)transportAttribute->children->content, WSDL_HTTP_TRANSPORT, sizeof(WSDL_HTTP_TRANSPORT)) == 0) { soapBinding->transport = SOAP_TRANSPORT_HTTP; } else { /* try the next binding */ @@ -913,7 +912,6 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) sdlSoapBindingFunctionPtr soapFunctionBinding; sdlSoapBindingPtr soapBinding; xmlNodePtr soapOperation; - xmlAttrPtr tmp; soapFunctionBinding = emalloc(sizeof(sdlSoapBindingFunction)); memset(soapFunctionBinding, 0, sizeof(sdlSoapBindingFunction)); @@ -922,14 +920,14 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) soapOperation = get_node_ex(operation->children, "operation", wsdl_soap_namespace); if (soapOperation) { - tmp = get_attribute(soapOperation->properties, "soapAction"); - if (tmp) { - soapFunctionBinding->soapAction = estrdup((char*)tmp->children->content); + xmlAttrPtr soapActionAttribute = get_attribute(soapOperation->properties, "soapAction"); + if (soapActionAttribute) { + soapFunctionBinding->soapAction = estrdup((char*)soapActionAttribute->children->content); } - tmp = get_attribute(soapOperation->properties, "style"); - if (tmp) { - if (!strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) { + xmlAttrPtr styleAttribute = get_attribute(soapOperation->properties, "style"); + if (styleAttribute) { + if (!strncmp((char*)styleAttribute->children->content, "rpc", sizeof("rpc"))) { soapFunctionBinding->style = SOAP_RPC; } else { soapFunctionBinding->style = SOAP_DOCUMENT; @@ -1013,11 +1011,11 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) fault = portTypeOperation->children; while (fault != NULL) { if (node_is_equal_ex(fault, "fault", WSDL_NAMESPACE)) { - xmlAttrPtr message, name; + xmlAttrPtr message; sdlFaultPtr f; - name = get_attribute(fault->properties, "name"); - if (name == NULL) { + xmlAttrPtr faultNameAttribute = get_attribute(fault->properties, "name"); + if (faultNameAttribute == NULL) { soap_error1(E_ERROR, "Parsing WSDL: Missing name for of '%s'", op_name->children->content); } message = get_attribute(fault->properties, "message"); @@ -1028,54 +1026,53 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) f = emalloc(sizeof(sdlFault)); memset(f, 0, sizeof(sdlFault)); - f->name = estrdup((char*)name->children->content); + f->name = estrdup((char*)faultNameAttribute->children->content); f->details = wsdl_message(&ctx, message->children->content); if (f->details == NULL || zend_hash_num_elements(f->details) > 1) { soap_error1(E_ERROR, "Parsing WSDL: The fault message '%s' must have a single part", message->children->content); } if (tmpbinding->bindingType == BINDING_SOAP) { - xmlNodePtr soap_fault = get_node_with_attribute_ex(operation->children, "fault", WSDL_NAMESPACE, "name", f->name, NULL); - if (soap_fault != NULL) { - xmlNodePtr trav = soap_fault->children; - while (trav != NULL) { - if (node_is_equal_ex(trav, "fault", wsdl_soap_namespace)) { - xmlAttrPtr tmp; - sdlSoapBindingFunctionFaultPtr binding; - - binding = f->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault)); + xmlNodePtr soapFault = get_node_with_attribute_ex(operation->children, "fault", WSDL_NAMESPACE, "name", f->name, NULL); + if (soapFault != NULL) { + xmlNodePtr faultNodes = soapFault->children; + while (faultNodes != NULL) { + if (node_is_equal_ex(faultNodes, "fault", wsdl_soap_namespace)) { + sdlSoapBindingFunctionFaultPtr faultBinding; + + faultBinding = f->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault)); memset(f->bindingAttributes, 0, sizeof(sdlSoapBindingFunctionFault)); - tmp = get_attribute(trav->properties, "use"); - if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) { - binding->use = SOAP_ENCODED; + xmlAttrPtr faultUseAttribute = get_attribute(faultNodes->properties, "use"); + if (faultUseAttribute && !strncmp((char*)faultUseAttribute->children->content, "encoded", sizeof("encoded"))) { + faultBinding->use = SOAP_ENCODED; } else { - binding->use = SOAP_LITERAL; + faultBinding->use = SOAP_LITERAL; } - tmp = get_attribute(trav->properties, "namespace"); - if (tmp) { - binding->ns = estrdup((char*)tmp->children->content); + xmlAttrPtr faultNamespaceAttribute = get_attribute(faultNodes->properties, "namespace"); + if (faultNamespaceAttribute) { + faultBinding->ns = estrdup((char*)faultNamespaceAttribute->children->content); } - if (binding->use == SOAP_ENCODED) { - tmp = get_attribute(trav->properties, "encodingStyle"); - if (tmp) { - if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) { - binding->encodingStyle = SOAP_ENCODING_1_1; - } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) { - binding->encodingStyle = SOAP_ENCODING_1_2; + if (faultBinding->use == SOAP_ENCODED) { + xmlAttrPtr faultEncodingStyleAttribute = get_attribute(faultNodes->properties, "encodingStyle"); + if (faultEncodingStyleAttribute) { + if (strncmp((char*)faultEncodingStyleAttribute->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) { + faultBinding->encodingStyle = SOAP_ENCODING_1_1; + } else if (strncmp((char*)faultEncodingStyleAttribute->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) { + faultBinding->encodingStyle = SOAP_ENCODING_1_2; } else { - soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content); + soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", faultEncodingStyleAttribute->children->content); } } else { soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle"); } } - } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav->name)); + } else if (is_wsdl_element(faultNodes) && !node_is_equal(faultNodes,"documentation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(faultNodes->name)); } - trav = trav->next; + faultNodes = faultNodes->next; } } } @@ -1093,24 +1090,24 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) function->binding = tmpbinding; { - char *tmp = estrdup(function->functionName); - size_t len = strlen(tmp); + size_t function_name_len = strlen(function->functionName); + char *lc_function_name = zend_str_tolower_dup(function->functionName, function_name_len); - zend_str_tolower(tmp, len); - if (zend_hash_str_add_ptr(&ctx.sdl->functions, tmp, len, function) == NULL) { + if (zend_hash_str_add_ptr(&ctx.sdl->functions, lc_function_name, function_name_len, function) == NULL) { zend_hash_next_index_insert_ptr(&ctx.sdl->functions, function); } - efree(tmp); + efree(lc_function_name); + if (function->requestName != NULL && strcmp(function->requestName,function->functionName) != 0) { if (ctx.sdl->requests == NULL) { ctx.sdl->requests = emalloc(sizeof(HashTable)); zend_hash_init(ctx.sdl->requests, 0, NULL, NULL, 0); } - tmp = estrdup(function->requestName); - len = strlen(tmp); - zend_str_tolower(tmp, len); - zend_hash_str_add_ptr(ctx.sdl->requests, tmp, len, function); - efree(tmp); + + size_t request_name_len = strlen(function->requestName); + char *lc_request_name = zend_str_tolower_dup(function->requestName, request_name_len); + zend_hash_str_add_ptr(ctx.sdl->requests, lc_request_name, request_name_len, function); + efree(lc_request_name); } } trav2 = trav2->next; From 2ea56fa17a3f05d70ec0de6cb00a1e2ef5cd3dac Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 16 Oct 2024 16:06:47 +0100 Subject: [PATCH 5/8] ext/soap: Check services are not empty via an if guard --- ext/soap/php_sdl.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 4466b539d1e14..2d08a721b6ba9 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -708,11 +708,14 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) zend_hash_init(&ctx.services, 0, NULL, NULL, 0); zend_try { - load_wsdl_ex(this_ptr, struri, &ctx, false); - schema_pass2(&ctx); + load_wsdl_ex(this_ptr, struri, &ctx, false); + schema_pass2(&ctx); + + uint32_t n = zend_hash_num_elements(&ctx.services); + if (n == 0) { + soap_error0(E_ERROR, "Parsing WSDL: Couldn't bind to service"); + } - uint32_t n = zend_hash_num_elements(&ctx.services); - if (n > 0) { zend_hash_internal_pointer_reset(&ctx.services); for (uint32_t i = 0; i < n; i++) { xmlNodePtr service, tmp; @@ -1126,13 +1129,10 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) zend_hash_move_forward(&ctx.services); } - } else { - soap_error0(E_ERROR, "Parsing WSDL: Couldn't bind to service"); - } - if (ctx.sdl->bindings == NULL || ctx.sdl->bindings->nNumOfElements == 0) { - soap_error0(E_ERROR, "Parsing WSDL: Could not find any usable binding services in WSDL."); - } + if (ctx.sdl->bindings == NULL || ctx.sdl->bindings->nNumOfElements == 0) { + soap_error0(E_ERROR, "Parsing WSDL: Could not find any usable binding services in WSDL."); + } } zend_catch { /* Avoid persistent memory leak. */ From ae8d6b8d018c108a0b17004398207f667642589b Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 16 Oct 2024 16:11:36 +0100 Subject: [PATCH 6/8] ext/soap: Indentation fix --- ext/soap/php_sdl.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 2d08a721b6ba9..a46d32a084bf8 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -564,15 +564,14 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap end = strchr(parts, ' '); if (end) *end = '\0'; ZEND_HASH_FOREACH_PTR(params, param) { - if (param->paramName && - strcmp(parts, param->paramName) == 0) { - sdlParamPtr x_param; - x_param = emalloc(sizeof(sdlParam)); - *x_param = *param; - param->paramName = NULL; - zend_hash_next_index_insert_ptr(&ht, x_param); - found = true; - break; + if (param->paramName && strcmp(parts, param->paramName) == 0) { + sdlParamPtr x_param; + x_param = emalloc(sizeof(sdlParam)); + *x_param = *param; + param->paramName = NULL; + zend_hash_next_index_insert_ptr(&ht, x_param); + found = true; + break; } } ZEND_HASH_FOREACH_END(); if (!found) { From 6c3a429f80223180f485ffdc6082cabb0d99e690 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 16 Oct 2024 16:16:16 +0100 Subject: [PATCH 7/8] ext/soap: Reduce scope and use proper names for XML attribute variables --- ext/soap/php_sdl.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index a46d32a084bf8..8c42906474add 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -528,29 +528,28 @@ static sdlSoapBindingFunctionHeaderPtr wsdl_soap_binding_header(sdlCtx* ctx, xml static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap_namespace, sdlSoapBindingFunctionBody *binding, HashTable* params) { xmlNodePtr trav; - xmlAttrPtr tmp; trav = node->children; while (trav != NULL) { if (node_is_equal_ex(trav, "body", wsdl_soap_namespace)) { xmlNodePtr body = trav; - tmp = get_attribute(body->properties, "use"); - if (tmp && !strncmp((char*)tmp->children->content, "literal", sizeof("literal"))) { + xmlAttrPtr useAttribute = get_attribute(body->properties, "use"); + if (useAttribute && !strncmp((char*)useAttribute->children->content, "literal", sizeof("literal"))) { binding->use = SOAP_LITERAL; } else { binding->use = SOAP_ENCODED; } - tmp = get_attribute(body->properties, "namespace"); - if (tmp) { - binding->ns = estrdup((char*)tmp->children->content); + xmlAttrPtr namespaceAttribute = get_attribute(body->properties, "namespace"); + if (namespaceAttribute) { + binding->ns = estrdup((char*)namespaceAttribute->children->content); } - tmp = get_attribute(body->properties, "parts"); - if (tmp) { + xmlAttrPtr partsAttribute = get_attribute(body->properties, "parts"); + if (partsAttribute) { HashTable ht; - char *parts = (char*)tmp->children->content; + char *parts = (char*)partsAttribute->children->content; /* Delete all parts those are not in the "parts" attribute */ zend_hash_init(&ht, 0, NULL, delete_parameter, 0); @@ -585,14 +584,14 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap } if (binding->use == SOAP_ENCODED) { - tmp = get_attribute(body->properties, "encodingStyle"); - if (tmp) { - if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) { + xmlAttrPtr encodingStyleAttribute = get_attribute(body->properties, "encodingStyle"); + if (encodingStyleAttribute) { + if (strncmp((char*)encodingStyleAttribute->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) { binding->encodingStyle = SOAP_ENCODING_1_1; - } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) { + } else if (strncmp((char*)encodingStyleAttribute->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) { binding->encodingStyle = SOAP_ENCODING_1_2; } else { - soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content); + soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", encodingStyleAttribute->children->content); } } else { soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle"); From 5e700e96abc888c3e2d6b40cb6052150938978ee Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 16 Oct 2024 16:22:18 +0100 Subject: [PATCH 8/8] ext/soap: Minor refactoring to wsdl_message() --- ext/soap/php_sdl.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 8c42906474add..5826c82c644ed 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -623,27 +623,26 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap } } -static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) +static HashTable* wsdl_message(const sdlCtx *ctx, const xmlChar* message_name) { - xmlNodePtr trav, message = NULL, tmp; HashTable* parameters = NULL; - char *ctype; - ctype = strrchr((char*)message_name,':'); + const char *ctype = strrchr((const char*)message_name,':'); if (ctype == NULL) { - ctype = (char*)message_name; + ctype = (const char*)message_name; } else { ++ctype; } - if ((tmp = zend_hash_str_find_ptr(&ctx->messages, ctype, strlen(ctype))) == NULL) { - soap_error1(E_ERROR, "Parsing WSDL: Missing with name '%s'", message_name); + + xmlNodePtr message = zend_hash_str_find_ptr(&ctx->messages, ctype, strlen(ctype)); + if (message == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing with name '%s'", (const char*)message_name); } - message = tmp; parameters = emalloc(sizeof(HashTable)); zend_hash_init(parameters, 0, NULL, delete_parameter, 0); - trav = message->children; + xmlNodePtr trav = message->children; while (trav != NULL) { xmlAttrPtr type, name; sdlParamPtr param;