com php-src: Fix #78473: odbc_close() closes arbitrar y resources: NEWS ext/odbc/php_odbc.c ext/odbc/te sts/bug78473.phpt
| From: | Christoph Michael Becker | Date: | Wed, 28 Aug 2019 15:55:15 +0000 |
| Subject: | com php-src: Fix #78473: odbc_close() closes arbitrar y resources: NEWS ext/odbc/php_odbc.c ext/odbc/te sts/bug78473.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-108115@lists.php.net to get a copy of this message | ||
Commit: b5572658166c4b8cbc1d332877a7a84c6e18a1c1
Author: Christoph M. Becker <cmbecker69@gmx.de> Wed, 28 Aug 2019 17:51:57 +0200
Parents: 88ab3746278c1e52aaba4dce264ae61431f94024
Branches: PHP-7.2 PHP-7..3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b5572658166c4b8cbc1d332877a7a84c6e18a1c1
Log:
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.
Bugs:
https://bugs.php.net/78473
Changed paths:
M NEWS
M ext/odbc/php_odbc.c
A ext/odbc/tests/bug78473.phpt
Diff:
diff --git a/NEWS b/NEWS
index e747a4f..838f1d2 100644
--- a/NEWS
+++ b/NEWS
@@ -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:
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index b5b8a07..33233d2 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -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;
}
diff --git a/ext/odbc/tests/bug78473.phpt b/ext/odbc/tests/bug78473.phpt
new file mode 100644
index 0000000..fd73b6c
--- /dev/null
+++ b/ext/odbc/tests/bug78473.phpt
@@ -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)