Skip to content

Commit

Permalink
Fix #78473: odbc_close() closes arbitrary resources
Browse files Browse the repository at this point in the history
We have to bail out, if an invalid resource is given.  For consistency
with the other `zend_fetch_resource(2)` calls, we return `FALSE`.
  • Loading branch information
cmb69 committed Aug 28, 2019
1 parent 88ab374 commit b557265
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ PHP NEWS
. Fixed connect_attr issues and added the _server_host connection attribute.
(Qianqian Bu)

- ODBC:
. Fixed bug #78473 (odbc_close() closes arbitrary resources). (cmb)

29 Aug 2019, PHP 7.2.22

- Core:
Expand Down
5 changes: 4 additions & 1 deletion ext/odbc/php_odbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2752,7 +2752,10 @@ PHP_FUNCTION(odbc_close)
return;
}

conn = (odbc_connection *)zend_fetch_resource2(Z_RES_P(pv_conn), "ODBC-Link", le_conn, le_pconn);
if (!(conn = (odbc_connection *)zend_fetch_resource2(Z_RES_P(pv_conn), "ODBC-Link", le_conn, le_pconn))) {
RETURN_FALSE;
}

if (Z_RES_P(pv_conn)->type == le_pconn) {
is_pconn = 1;
}
Expand Down
14 changes: 14 additions & 0 deletions ext/odbc/tests/bug78473.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Bug #78473 (odbc_close() closes arbitrary resources)
--SKIPIF--
<?php
if (!extension_loaded('odbc')) die('skip odbc extension not available');
?>
--FILE--
<?php
odbc_close(STDIN);
var_dump(STDIN);
?>
--EXPECTF--
Warning: odbc_close(): supplied resource is not a valid ODBC-Link resource in %s on line %d
resource(%d) of type (stream)

0 comments on commit b557265

Please sign in to comment.