Skip to content

Commit 5da0579

Browse files
committed
Fixed bug #77945
Make sure that we proper distinguish between empty string key and no key during SDL serialization.
1 parent 9bf1104 commit 5da0579

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ PHP NEWS
5858
. Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita)
5959
. Fixed bug #77882 (Different behavior: always calls destructor). (Nikita)
6060

61+
- SOAP:
62+
. Fixed bug #77945 (Segmentation fault when constructing SoapClient with
63+
WSDL_CACHE_BOTH). (Nikita)
64+
6165
- Standard:
6266
. Fixed bug #77680 (recursive mkdir on ftp stream wrapper is incorrect).
6367
(Vlad Temian)

ext/soap/php_sdl.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri)
11741174
return ctx.sdl;
11751175
}
11761176

1177-
#define WSDL_CACHE_VERSION 0x0f
1177+
#define WSDL_CACHE_VERSION 0x10
11781178

11791179
#define WSDL_CACHE_GET(ret,type,buf) memcpy(&ret,*buf,sizeof(type)); *buf += sizeof(type);
11801180
#define WSDL_CACHE_GET_INT(ret,buf) ret = ((unsigned char)(*buf)[0])|((unsigned char)(*buf)[1]<<8)|((unsigned char)(*buf)[2]<<16)|((int)(*buf)[3]<<24); *buf += 4;
@@ -1189,13 +1189,15 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri)
11891189
#define WSDL_CACHE_PUT_1(val,buf) smart_str_appendc(buf,val);
11901190
#define WSDL_CACHE_PUT_N(val,n,buf) smart_str_appendl(buf,(char*)val,n);
11911191

1192+
#define WSDL_NO_STRING_MARKER 0x7fffffff
1193+
11921194
static char* sdl_deserialize_string(char **in)
11931195
{
11941196
char *s;
11951197
int len;
11961198

11971199
WSDL_CACHE_GET_INT(len, in);
1198-
if (len == 0x7fffffff) {
1200+
if (len == WSDL_NO_STRING_MARKER) {
11991201
return NULL;
12001202
} else {
12011203
s = emalloc(len+1);
@@ -1210,7 +1212,7 @@ static void sdl_deserialize_key(HashTable* ht, void* data, char **in)
12101212
int len;
12111213

12121214
WSDL_CACHE_GET_INT(len, in);
1213-
if (len == 0) {
1215+
if (len == WSDL_NO_STRING_MARKER) {
12141216
zend_hash_next_index_insert_ptr(ht, data);
12151217
} else {
12161218
zend_hash_str_add_ptr(ht, *in, len, data);
@@ -1778,16 +1780,14 @@ static sdlPtr get_sdl_from_cache(const char *fn, const char *uri, time_t t, time
17781780

17791781
static void sdl_serialize_string(const char *str, smart_str *out)
17801782
{
1781-
int i;
1782-
17831783
if (str) {
1784-
i = strlen(str);
1784+
int i = strlen(str);
17851785
WSDL_CACHE_PUT_INT(i, out);
17861786
if (i > 0) {
17871787
WSDL_CACHE_PUT_N(str, i, out);
17881788
}
17891789
} else {
1790-
WSDL_CACHE_PUT_INT(0x7fffffff, out);
1790+
WSDL_CACHE_PUT_INT(WSDL_NO_STRING_MARKER, out);
17911791
}
17921792
}
17931793

@@ -1798,7 +1798,7 @@ static void sdl_serialize_key(zend_string *key, smart_str *out)
17981798
WSDL_CACHE_PUT_INT(ZSTR_LEN(key), out);
17991799
WSDL_CACHE_PUT_N(ZSTR_VAL(key), ZSTR_LEN(key), out);
18001800
} else {
1801-
WSDL_CACHE_PUT_INT(0, out);
1801+
WSDL_CACHE_PUT_INT(WSDL_NO_STRING_MARKER, out);
18021802
}
18031803
}
18041804

ext/soap/tests/bugs/bug29236.wsdl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<s:enumeration value="TemporarilySuspended" />
7676
<s:enumeration value="PasswordResetRequired" />
7777
<s:enumeration value="InvalidID" />
78+
<s:enumeration value="" /> <!-- For bug #77945 -->
7879
</s:restriction>
7980
</s:simpleType>
8081
<s:simpleType name="SessionStatus">
@@ -284,4 +285,4 @@
284285
<http:address location="http://isisdev1.tig.ucla.edu/iws/v4.asmx" />
285286
</port>
286287
</service>
287-
</definitions>
288+
</definitions>

ext/soap/tests/bugs/bug77945.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #77945: Segmentation fault when constructing SoapClient with WSDL_CACHE_BOTH
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('soap')) die('skip soap extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
// The important part is to have a restriction enumeration with value="".
11+
$client = new SoapClient(__DIR__ . '/bug29236.wsdl', [
12+
'cache_wsdl' => WSDL_CACHE_BOTH
13+
]);
14+
15+
?>
16+
===DONE===
17+
--EXPECT--
18+
===DONE===

0 commit comments

Comments
 (0)