Skip to content

Avoid copying the local name in SOAP's parse_namespace() #15862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ext/soap/php_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ static zval *master_to_zval_int(zval *ret, encodePtr encode, xmlNodePtr data)
if (type_attr != NULL) {
encodePtr new_enc;
xmlNsPtr nsptr;
char *ns, *cptype;
const char *cptype;
char *ns;
smart_str nscat = {0};

parse_namespace(type_attr->children->content, &cptype, &ns);
Expand All @@ -549,7 +550,6 @@ static zval *master_to_zval_int(zval *ret, encodePtr encode, xmlNodePtr data)
}
smart_str_appends(&nscat, cptype);
smart_str_0(&nscat);
efree(cptype);
if (ns) {efree(ns);}
if ((new_enc = zend_hash_find_ptr(SOAP_GLOBAL(typemap), nscat.s)) != NULL) {
encode = new_enc;
Expand Down Expand Up @@ -2466,7 +2466,8 @@ static zval *to_zval_array(zval *ret, encodeTypePtr type, xmlNodePtr data)
if (data &&
(attr = get_attribute(data->properties,"arrayType")) &&
attr->children && attr->children->content) {
char *type, *end, *ns;
const char *type;
char *end, *ns;
xmlNsPtr nsptr;

parse_namespace(attr->children->content, &type, &ns);
Expand All @@ -2481,21 +2482,20 @@ static zval *to_zval_array(zval *ret, encodeTypePtr type, xmlNodePtr data)
if (nsptr != NULL) {
enc = get_encoder(SOAP_GLOBAL(sdl), (char*)nsptr->href, type);
}
efree(type);
if (ns) {efree(ns);}

} else if ((attr = get_attribute(data->properties,"itemType")) &&
attr->children &&
attr->children->content) {
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

parse_namespace(attr->children->content, &type, &ns);
nsptr = xmlSearchNs(attr->doc, attr->parent, BAD_CAST(ns));
if (nsptr != NULL) {
enc = get_encoder(SOAP_GLOBAL(sdl), (char*)nsptr->href, type);
}
efree(type);
if (ns) {efree(ns);}

if ((attr = get_attribute(data->properties,"arraySize")) &&
Expand Down Expand Up @@ -2828,7 +2828,8 @@ static zval *guess_zval_convert(zval *ret, encodeTypePtr type, xmlNodePtr data)
master_to_zval_int(ret, enc, data);
if (SOAP_GLOBAL(sdl) && type_name && enc->details.sdl_type) {
zval soapvar;
char *ns, *cptype;
const char *cptype;
char *ns;
xmlNsPtr nsptr;

object_init_ex(&soapvar, soap_var_class_entry);
Expand All @@ -2840,7 +2841,6 @@ static zval *guess_zval_convert(zval *ret, encodeTypePtr type, xmlNodePtr data)
if (nsptr) {
ZVAL_STRING(Z_VAR_ENC_NS_P(&soapvar), (char*)nsptr->href);
}
efree(cptype);
if (ns) {efree(ns);}
ZVAL_COPY_VALUE(ret, &soapvar);
}
Expand Down
52 changes: 26 additions & 26 deletions ext/soap/php_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ static int schema_list(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr listType, sdlTypeP

itemType = get_attribute(listType->properties, "itemType");
if (itemType != NULL) {
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

parse_namespace(itemType->children->content, &type, &ns);
Expand All @@ -436,7 +437,6 @@ static int schema_list(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr listType, sdlTypeP
}
zend_hash_next_index_insert_ptr(cur_type->elements, newType);
}
if (type) {efree(type);}
if (ns) {efree(ns);}
}

Expand Down Expand Up @@ -498,7 +498,8 @@ static int schema_union(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr unionType, sdlTyp
memberTypes = get_attribute(unionType->properties, "memberTypes");
if (memberTypes != NULL) {
char *str, *start, *end, *next;
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

str = estrdup((char*)memberTypes->children->content);
Expand Down Expand Up @@ -532,7 +533,6 @@ static int schema_union(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr unionType, sdlTyp
}
zend_hash_next_index_insert_ptr(cur_type->elements, newType);
}
if (type) {efree(type);}
if (ns) {efree(ns);}

start = next;
Expand Down Expand Up @@ -641,15 +641,15 @@ static int schema_restriction_simpleContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodeP

base = get_attribute(restType->properties, "base");
if (base != NULL) {
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

parse_namespace(base->children->content, &type, &ns);
nsptr = xmlSearchNs(restType->doc, restType, BAD_CAST(ns));
if (nsptr != NULL) {
cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(type));
}
if (type) {efree(type);}
if (ns) {efree(ns);}
} else if (!simpleType) {
soap_error0(E_ERROR, "Parsing Schema: restriction has no 'base' attribute");
Expand Down Expand Up @@ -746,15 +746,15 @@ static int schema_restriction_complexContent(sdlPtr sdl, xmlAttrPtr tns, xmlNode

base = get_attribute(restType->properties, "base");
if (base != NULL) {
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

parse_namespace(base->children->content, &type, &ns);
nsptr = xmlSearchNs(restType->doc, restType, BAD_CAST(ns));
if (nsptr != NULL) {
cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(type));
}
if (type) {efree(type);}
if (ns) {efree(ns);}
} else {
soap_error0(E_ERROR, "Parsing Schema: restriction has no 'base' attribute");
Expand Down Expand Up @@ -871,15 +871,15 @@ static int schema_extension_simpleContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr

base = get_attribute(extType->properties, "base");
if (base != NULL) {
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

parse_namespace(base->children->content, &type, &ns);
nsptr = xmlSearchNs(extType->doc, extType, BAD_CAST(ns));
if (nsptr != NULL) {
cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(type));
}
if (type) {efree(type);}
if (ns) {efree(ns);}
} else {
soap_error0(E_ERROR, "Parsing Schema: extension has no 'base' attribute");
Expand Down Expand Up @@ -926,15 +926,15 @@ static int schema_extension_complexContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePt

base = get_attribute(extType->properties, "base");
if (base != NULL) {
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

parse_namespace(base->children->content, &type, &ns);
nsptr = xmlSearchNs(extType->doc, extType, BAD_CAST(ns));
if (nsptr != NULL) {
cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(type));
}
if (type) {efree(type);}
if (ns) {efree(ns);}
} else {
soap_error0(E_ERROR, "Parsing Schema: extension has no 'base' attribute");
Expand Down Expand Up @@ -1075,7 +1075,8 @@ static int schema_group(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr groupType, sdlTyp
smart_str key = {0};

if (ref) {
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

parse_namespace(ref->children->content, &type, &ns);
Expand All @@ -1099,7 +1100,6 @@ static int schema_group(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr groupType, sdlTyp
newModel->kind = XSD_CONTENT_GROUP_REF;
newModel->u.group_ref = estrndup(ZSTR_VAL(key.s), ZSTR_LEN(key.s));

if (type) {efree(type);}
if (ns) {efree(ns);}
} else {
newModel = emalloc(sizeof(sdlContentModel));
Expand Down Expand Up @@ -1513,7 +1513,8 @@ static int schema_element(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr element, sdlTyp

if (ref) {
smart_str nscat = {0};
char *type, *ns;
const char *type;
char *ns;
xmlNsPtr nsptr;

parse_namespace(ref->children->content, &type, &ns);
Expand All @@ -1534,7 +1535,6 @@ static int schema_element(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr element, sdlTyp
smart_str_appends(&nscat, type);
newType->name = estrdup(type);
smart_str_0(&nscat);
if (type) {efree(type);}
if (ns) {efree(ns);}
newType->ref = estrndup(ZSTR_VAL(nscat.s), ZSTR_LEN(nscat.s));
smart_str_free(&nscat);
Expand Down Expand Up @@ -1658,7 +1658,8 @@ static int schema_element(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr element, sdlTyp
/* type = QName */
type = get_attribute(attrs, "type");
if (type) {
char *cptype, *str_ns;
const char *cptype;
char *str_ns;
xmlNsPtr nsptr;

if (ref != NULL) {
Expand All @@ -1670,7 +1671,6 @@ static int schema_element(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr element, sdlTyp
cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(cptype));
}
if (str_ns) {efree(str_ns);}
if (cptype) {efree(cptype);}
}

trav = element->children;
Expand Down Expand Up @@ -1745,7 +1745,8 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdl
memset(newAttr, 0, sizeof(sdlAttribute));

if (ref) {
char *attr_name, *ns;
const char *attr_name;
char *ns;
xmlNsPtr nsptr;

parse_namespace(ref->children->content, &attr_name, &ns);
Expand All @@ -1766,7 +1767,6 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdl
smart_str_appends(&key, attr_name);
smart_str_0(&key);
newAttr->ref = estrndup(ZSTR_VAL(key.s), ZSTR_LEN(key.s));
if (attr_name) {efree(attr_name);}
if (ns) {efree(ns);}
} else {
xmlAttrPtr ns;
Expand Down Expand Up @@ -1806,7 +1806,8 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdl
/* type = QName */
type = get_attribute(attrType->properties, "type");
if (type) {
char *cptype, *str_ns;
const char *cptype;
char *str_ns;
xmlNsPtr nsptr;

if (ref != NULL) {
Expand All @@ -1818,7 +1819,6 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdl
newAttr->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(cptype));
}
if (str_ns) {efree(str_ns);}
if (cptype) {efree(cptype);}
}

attr = attrType->properties;
Expand Down Expand Up @@ -1860,7 +1860,8 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdl
smart_str key2 = {0};
sdlExtraAttributePtr ext;
xmlNsPtr nsptr;
char *value, *ns;
const char *value;
char *ns;

ext = emalloc(sizeof(sdlExtraAttribute));
memset(ext, 0, sizeof(sdlExtraAttribute));
Expand All @@ -1873,7 +1874,6 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdl
ext->val = estrdup((char*)attr->children->content);
}
if (ns) {efree(ns);}
efree(value);

if (!newAttr->extraAttributes) {
newAttr->extraAttributes = emalloc(sizeof(HashTable));
Expand Down Expand Up @@ -1986,7 +1986,8 @@ static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrGrou
smart_str_free(&key);
} else if (ref) {
sdlAttributePtr newAttr;
char *group_name, *ns;
const char *group_name;
char *ns;
smart_str key = {0};
xmlNsPtr nsptr;

Expand All @@ -2006,7 +2007,6 @@ static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrGrou
smart_str_appends(&key, group_name);
smart_str_0(&key);
newAttr->ref = estrndup(ZSTR_VAL(key.s), ZSTR_LEN(key.s));
if (group_name) {efree(group_name);}
if (ns) {efree(ns);}
smart_str_free(&key);

Expand Down
8 changes: 4 additions & 4 deletions ext/soap/php_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr node, const xmlChar *ty
{
encodePtr enc = NULL;
xmlNsPtr nsptr;
char *ns, *cptype;
const char *cptype;
char *ns;

parse_namespace(type, &cptype, &ns);
nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns));
Expand All @@ -60,7 +61,6 @@ encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr node, const xmlChar *ty
} else {
enc = get_encoder_ex(sdl, (char*)type, xmlStrlen(type));
}
efree(cptype);
if (ns) {efree(ns);}
return enc;
}
Expand All @@ -71,7 +71,8 @@ static sdlTypePtr get_element(sdlPtr sdl, xmlNodePtr node, const xmlChar *type)

if (sdl->elements) {
xmlNsPtr nsptr;
char *ns, *cptype;
const char *cptype;
char *ns;
sdlTypePtr sdl_type;

parse_namespace(type, &cptype, &ns);
Expand Down Expand Up @@ -99,7 +100,6 @@ static sdlTypePtr get_element(sdlPtr sdl, xmlNodePtr node, const xmlChar *type)
}
}

efree(cptype);
if (ns) {efree(ns);}
}
return ret;
Expand Down
15 changes: 7 additions & 8 deletions ext/soap/php_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,16 @@ xmlNodePtr get_node_with_attribute_recursive_ex(xmlNodePtr node, char *name, cha
return NULL;
}

int parse_namespace(const xmlChar *inval, char **value, char **namespace)
/* namespace is either a copy or NULL, value is never NULL and never a copy. */
void parse_namespace(const xmlChar *inval, const char **value, char **namespace)
{
char *found = strrchr((char*)inval, ':');
const char *found = strrchr((const char *) inval, ':');

if (found != NULL && found != (char*)inval) {
(*namespace) = estrndup((char*)inval, found - (char*)inval);
(*value) = estrdup(++found);
if (found != NULL && found != (const char *) inval) {
(*namespace) = estrndup((const char *) inval, found - (const char *) inval);
(*value) = ++found;
} else {
(*value) = estrdup((char*)inval);
(*value) = (const char *) inval;
(*namespace) = NULL;
}

return FALSE;
}
2 changes: 1 addition & 1 deletion ext/soap/php_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ xmlNodePtr get_node_ex(xmlNodePtr node,char *name, char *ns);
xmlNodePtr get_node_recursive_ex(xmlNodePtr node,char *name, char *ns);
xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns);
xmlNodePtr get_node_with_attribute_recursive_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns);
int parse_namespace(const xmlChar *inval,char **value,char **namespace);
void parse_namespace(const xmlChar *inval, const char **value, char **namespace);

#define FOREACHATTRNODE(n,c,i) FOREACHATTRNODEEX(n,c,NULL,i)
#define FOREACHATTRNODEEX(n,c,ns,i) \
Expand Down
Loading