Skip to content

Commit 133ac01

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #44618: Fetching may rely on uninitialized data
2 parents 24537a7 + c21e901 commit 133ac01

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ PHP NEWS
2626
. Fixed bug #80242 (imap_mail_compose() segfaults for multipart with rfc822).
2727
(cmb)
2828

29+
- ODBC:
30+
. Fixed bug #44618 (Fetching may rely on uninitialized data). (cmb)
31+
2932
- Opcache:
3033
. Fixed bug #79643 (PHP with Opcache crashes when a file with specific name
3134
is included). (twosee)

ext/odbc/php_odbc.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,9 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
18081808

18091809
if (rc == SQL_SUCCESS_WITH_INFO) {
18101810
ZVAL_STRINGL(&tmp, buf, result->longreadlen);
1811+
} else if (rc != SQL_SUCCESS) {
1812+
php_error_docref(NULL, E_WARNING, "Cannot get data of column #%d (retcode %u)", i + 1, rc);
1813+
ZVAL_FALSE(&tmp);
18111814
} else if (result->values[i].vallen == SQL_NULL_DATA) {
18121815
ZVAL_NULL(&tmp);
18131816
break;
@@ -1961,6 +1964,9 @@ PHP_FUNCTION(odbc_fetch_into)
19611964
}
19621965
if (rc == SQL_SUCCESS_WITH_INFO) {
19631966
ZVAL_STRINGL(&tmp, buf, result->longreadlen);
1967+
} else if (rc != SQL_SUCCESS) {
1968+
php_error_docref(NULL, E_WARNING, "Cannot get data of column #%d (retcode %u)", i + 1, rc);
1969+
ZVAL_FALSE(&tmp);
19641970
} else if (result->values[i].vallen == SQL_NULL_DATA) {
19651971
ZVAL_NULL(&tmp);
19661972
break;
@@ -2198,12 +2204,13 @@ PHP_FUNCTION(odbc_result)
21982204
RETURN_FALSE;
21992205
}
22002206

2201-
if (result->values[field_ind].vallen == SQL_NULL_DATA) {
2202-
zend_string_efree(field_str);
2203-
RETURN_NULL();
2204-
} else if (rc == SQL_NO_DATA_FOUND) {
2207+
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
22052208
zend_string_efree(field_str);
2209+
php_error_docref(NULL, E_WARNING, "Cannot get data of column #%d (retcode %u)", field_ind + 1, rc);
22062210
RETURN_FALSE;
2211+
} else if (result->values[field_ind].vallen == SQL_NULL_DATA) {
2212+
zend_string_efree(field_str);
2213+
RETURN_NULL();
22072214
}
22082215
/* Reduce fieldlen by 1 if we have char data. One day we might
22092216
have binary strings... */
@@ -2249,6 +2256,12 @@ PHP_FUNCTION(odbc_result)
22492256
RETURN_FALSE;
22502257
}
22512258

2259+
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
2260+
php_error_docref(NULL, E_WARNING, "Cannot get data of column #%d (retcode %u)", field_ind + 1, rc);
2261+
efree(field);
2262+
RETURN_FALSE;
2263+
}
2264+
22522265
if (result->values[field_ind].vallen == SQL_NULL_DATA) {
22532266
efree(field);
22542267
RETURN_NULL();
@@ -2358,6 +2371,11 @@ PHP_FUNCTION(odbc_result_all)
23582371
}
23592372
if (rc == SQL_SUCCESS_WITH_INFO) {
23602373
PHPWRITE(buf, result->longreadlen);
2374+
} else if (rc != SQL_SUCCESS) {
2375+
php_printf("</td></tr></table>");
2376+
php_error_docref(NULL, E_WARNING, "Cannot get data of column #%d (retcode %u)", i + 1, rc);
2377+
efree(buf);
2378+
RETURN_FALSE;
23612379
} else if (result->values[i].vallen == SQL_NULL_DATA) {
23622380
php_printf("<td>NULL</td>");
23632381
break;

ext/odbc/tests/bug44618.phpt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
Bug #44618 (Fetching may rely on uninitialized data)
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
include __DIR__ . "/config.inc";
8+
$conn = odbc_connect($dsn, $user, $pass, SQL_CUR_USE_ODBC);
9+
10+
odbc_exec($conn, "CREATE TABLE bug44618(ID INT, real1 REAL, text1 TEXT)");
11+
odbc_exec($conn, "INSERT INTO bug44618 VALUES (1, 10.0199995, 'testing 1,2,3')");
12+
13+
$result = odbc_exec($conn, "SELECT * FROM bug44618");
14+
var_dump(odbc_fetch_array($result));
15+
$result = null;
16+
17+
$result = odbc_exec($conn, "SELECT * FROM bug44618");
18+
odbc_fetch_into($result, $array);
19+
var_dump($array);
20+
$result = null;
21+
22+
$result = odbc_exec($conn, "SELECT * FROM bug44618");
23+
odbc_fetch_row($result);
24+
var_dump(odbc_result($result, "text1"));
25+
$result = null;
26+
27+
$result = odbc_exec($conn, "SELECT * FROM bug44618");
28+
odbc_result_all($result);
29+
$result = null;
30+
?>
31+
--CLEAN--
32+
<?php
33+
include __DIR__ . "/config.inc";
34+
$conn = odbc_connect($dsn, $user, $pass);
35+
odbc_exec($conn, "DROP TABLE bug44618");
36+
?>
37+
--EXPECTF--
38+
Warning: odbc_fetch_array(): Cannot get data of column #3 (retcode 100) in %s on line %d
39+
array(3) {
40+
["ID"]=>
41+
string(1) "1"
42+
["real1"]=>
43+
string(5) "10.02"
44+
["text1"]=>
45+
bool(false)
46+
}
47+
48+
Warning: odbc_fetch_into(): Cannot get data of column #3 (retcode 100) in %s on line %d
49+
array(3) {
50+
[0]=>
51+
string(1) "1"
52+
[1]=>
53+
string(5) "10.02"
54+
[2]=>
55+
bool(false)
56+
}
57+
58+
Warning: odbc_result(): Cannot get data of column #3 (retcode 100) in %s on line %d
59+
bool(false)
60+
<table><tr><th>ID</th><th>real1</th><th>text1</th></tr>
61+
<tr><td>1</td><td>10.02</td><td></td></tr></table>
62+
Warning: odbc_result_all(): Cannot get data of column #3 (retcode 100) in %s on line %d

0 commit comments

Comments
 (0)