Skip to content

Commit b557265

Browse files
committed
Fix #78473: odbc_close() closes arbitrary resources
We have to bail out, if an invalid resource is given. For consistency with the other `zend_fetch_resource(2)` calls, we return `FALSE`.
1 parent 88ab374 commit b557265

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
. Fixed connect_attr issues and added the _server_host connection attribute.
1212
(Qianqian Bu)
1313

14+
- ODBC:
15+
. Fixed bug #78473 (odbc_close() closes arbitrary resources). (cmb)
16+
1417
29 Aug 2019, PHP 7.2.22
1518

1619
- Core:

ext/odbc/php_odbc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,10 @@ PHP_FUNCTION(odbc_close)
27522752
return;
27532753
}
27542754

2755-
conn = (odbc_connection *)zend_fetch_resource2(Z_RES_P(pv_conn), "ODBC-Link", le_conn, le_pconn);
2755+
if (!(conn = (odbc_connection *)zend_fetch_resource2(Z_RES_P(pv_conn), "ODBC-Link", le_conn, le_pconn))) {
2756+
RETURN_FALSE;
2757+
}
2758+
27562759
if (Z_RES_P(pv_conn)->type == le_pconn) {
27572760
is_pconn = 1;
27582761
}

ext/odbc/tests/bug78473.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #78473 (odbc_close() closes arbitrary resources)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('odbc')) die('skip odbc extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
odbc_close(STDIN);
10+
var_dump(STDIN);
11+
?>
12+
--EXPECTF--
13+
Warning: odbc_close(): supplied resource is not a valid ODBC-Link resource in %s on line %d
14+
resource(%d) of type (stream)

0 commit comments

Comments
 (0)