Skip to content

Commit 16d949d

Browse files
committed
Reject Negative values
1 parent 5427a74 commit 16d949d

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ PHP NEWS
177177
. Fixed bug GH-21421 (SoapClient typemap property breaks engine assumptions).
178178
(ndossche)
179179
. Fixed bug GH-22167 (Out-of-range XML Schema integer values were silently
180-
accepted during WSDL parsing). (Weilin Du)
180+
accepted during WSDL parsing; negative occurrence values are now rejected).
181+
(Weilin Du)
181182

182183
- Sockets:
183184
. Added the TCP_USER_TIMEOUT constant for Linux to set the maximum time in

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ PHP 8.6 UPGRADE NOTES
341341
- mysqli
342342
. Added new constant MYSQLI_OPT_COMPRESS.
343343

344+
- Soap:
345+
. WSDL/XML Schema parsing now rejects out-of-range integer values for
346+
occurrence constraints and integer restriction facets. Negative minOccurs
347+
and maxOccurs values are rejected as well.
348+
344349
========================================
345350
10. New Global Constants
346351
========================================

ext/soap/php_schema.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,29 @@ static bool node_is_equal_xsd(xmlNodePtr node, const char *name)
5353
return node_is_equal_ex_one_of(node, name, ns);
5454
}
5555

56-
static int schema_parse_int(const xmlChar *value, const char *name)
56+
static int schema_parse_int(const xmlChar *value, const char *name, bool allow_negative)
5757
{
5858
const char *str = (const char *) value;
5959
zend_long lval = 0;
6060
int oflow_info = 0;
6161
uint8_t type = is_numeric_string_ex(str, strlen(str), &lval, NULL, true, &oflow_info, NULL);
6262

63-
if (oflow_info > 0 || (type == IS_LONG && ZEND_LONG_INT_OVFL(lval))) {
63+
if (oflow_info || (type == IS_LONG && ZEND_LONG_EXCEEDS_INT(lval))) {
6464
soap_error1(E_ERROR, "Parsing Schema: %s value is out of range", name);
6565
}
6666

6767
if (type == IS_LONG) {
68+
if (!allow_negative && lval < 0) {
69+
soap_error1(E_ERROR, "Parsing Schema: %s value is out of range", name);
70+
}
6871
return (int) lval;
6972
}
7073

7174
errno = 0;
7275
lval = ZEND_STRTOL(str, NULL, 10);
73-
if ((errno == ERANGE && lval > 0) || ZEND_LONG_INT_OVFL(lval)) {
76+
if ((errno == ERANGE && (lval > 0 || lval < 0))
77+
|| ZEND_LONG_EXCEEDS_INT(lval)
78+
|| (!allow_negative && lval < 0)) {
7479
soap_error1(E_ERROR, "Parsing Schema: %s value is out of range", name);
7580
}
7681

@@ -878,7 +883,7 @@ static int schema_restriction_var_int(xmlNodePtr val, sdlRestrictionIntPtr *valp
878883
soap_error0(E_ERROR, "Parsing Schema: missing restriction value");
879884
}
880885

881-
(*valptr)->value = schema_parse_int(value->children->content, (const char *) val->name);
886+
(*valptr)->value = schema_parse_int(value->children->content, (const char *) val->name, true);
882887

883888
return TRUE;
884889
}
@@ -1040,7 +1045,7 @@ void schema_min_max(xmlNodePtr node, sdlContentModelPtr model)
10401045
xmlAttrPtr attr = get_attribute(node->properties, "minOccurs");
10411046

10421047
if (attr) {
1043-
model->min_occurs = schema_parse_int(attr->children->content, "minOccurs");
1048+
model->min_occurs = schema_parse_int(attr->children->content, "minOccurs", false);
10441049
} else {
10451050
model->min_occurs = 1;
10461051
}
@@ -1050,7 +1055,7 @@ void schema_min_max(xmlNodePtr node, sdlContentModelPtr model)
10501055
if (!strncmp((char*)attr->children->content, "unbounded", sizeof("unbounded"))) {
10511056
model->max_occurs = -1;
10521057
} else {
1053-
model->max_occurs = schema_parse_int(attr->children->content, "maxOccurs");
1058+
model->max_occurs = schema_parse_int(attr->children->content, "maxOccurs", false);
10541059
}
10551060
} else {
10561061
model->max_occurs = 1;

ext/soap/tests/bugs/gh22167.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ XML;
6161
$cases = [
6262
"minOccurs" => occurrence_schema("minOccurs"),
6363
"maxOccurs" => occurrence_schema("maxOccurs"),
64+
"negative minOccurs" => occurrence_schema("minOccurs", "-1"),
65+
"negative maxOccurs" => occurrence_schema("maxOccurs", "-1"),
6466
"minExclusive" => restriction_schema("minExclusive"),
6567
"minInclusive" => restriction_schema("minInclusive"),
6668
"maxExclusive" => restriction_schema("maxExclusive"),
@@ -77,6 +79,7 @@ $numeric_string_cases = [
7779
"leading plus numeric-string" => "+2147483648",
7880
"leading zero numeric-string" => "00000000002147483648",
7981
"leading numeric-string with trailing data" => "2147483648abc",
82+
"negative out-of-range numeric-string" => "-2147483649",
8083
"decimal numeric-string" => "2147483648.0",
8184
"exponent numeric-string" => "2147483648e0",
8285
];
@@ -104,6 +107,8 @@ foreach ($cases as $name => $schema) {
104107
--EXPECT--
105108
minOccurs: SOAP-ERROR: Parsing Schema: minOccurs value is out of range
106109
maxOccurs: SOAP-ERROR: Parsing Schema: maxOccurs value is out of range
110+
negative minOccurs: SOAP-ERROR: Parsing Schema: minOccurs value is out of range
111+
negative maxOccurs: SOAP-ERROR: Parsing Schema: maxOccurs value is out of range
107112
minExclusive: SOAP-ERROR: Parsing Schema: minExclusive value is out of range
108113
minInclusive: SOAP-ERROR: Parsing Schema: minInclusive value is out of range
109114
maxExclusive: SOAP-ERROR: Parsing Schema: maxExclusive value is out of range
@@ -117,6 +122,7 @@ leading whitespace numeric-string: SOAP-ERROR: Parsing Schema: maxOccurs value i
117122
leading plus numeric-string: SOAP-ERROR: Parsing Schema: maxOccurs value is out of range
118123
leading zero numeric-string: SOAP-ERROR: Parsing Schema: maxOccurs value is out of range
119124
leading numeric-string with trailing data: SOAP-ERROR: Parsing Schema: maxOccurs value is out of range
125+
negative out-of-range numeric-string: SOAP-ERROR: Parsing Schema: maxOccurs value is out of range
120126
decimal numeric-string: SOAP-ERROR: Parsing Schema: maxOccurs value is out of range
121127
exponent numeric-string: SOAP-ERROR: Parsing Schema: maxOccurs value is out of range
122128
fractional numeric-string within int range: parsed

0 commit comments

Comments
 (0)