Skip to content

Commit 5e2b834

Browse files
committed
Check the return value of dbconvert() in mssql_guid_string(), as it may return -1 in case the conversion failed. In that case false is returned.
Also initialize buffer and buffer2 to NULL, which should fix bug #72039 (Use of uninitialised value on mssql_guid_string). This only applies to 5.6, as we do not have mssql in 7.0 anymore
1 parent 65056e9 commit 5e2b834

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2016, PHP 5.6.26
44

5+
- MSSQL:
6+
. Fixed bug #72039 (Use of uninitialised value on mssql_guid_string). (Kalle)
7+
58
18 Aug 2016, PHP 5.6.25
69

710
- Core:

ext/mssql/php_mssql.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,21 +2235,24 @@ PHP_FUNCTION(mssql_guid_string)
22352235
char *binary;
22362236
int binary_len;
22372237
zend_bool sf = 0;
2238-
char buffer[32+1];
2239-
char buffer2[36+1];
2238+
char buffer[32+1] = NULL;
22402239

22412240
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &binary, &binary_len, &sf) == FAILURE) {
22422241
return;
22432242
}
22442243

2245-
dbconvert(NULL, SQLBINARY, (BYTE*) binary, MIN(16, binary_len), SQLCHAR, buffer, -1);
2244+
if (dbconvert(NULL, SQLBINARY, (BYTE*) binary, MIN(16, binary_len), SQLCHAR, buffer, (DBINT) -1) == -1) {
2245+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not convert binary string to GUID string");
2246+
RETURN_FALSE;
2247+
}
22462248

22472249
if (sf) {
22482250
php_strtoupper(buffer, 32);
22492251
RETURN_STRING(buffer, 1);
2250-
}
2251-
else {
2252+
} else {
22522253
int i;
2254+
char buffer2[36+1] = NULL;
2255+
22532256
/* FIXME this works only on little endian machine */
22542257
for (i=0; i<4; i++) {
22552258
buffer2[2*i] = buffer[6-2*i];

0 commit comments

Comments
 (0)