Skip to content

Commit

Permalink
Fix GH-7765: php_oci_cleanup_global_handles segfaults at second call
Browse files Browse the repository at this point in the history
We must not use the TSRM accessor macros in GINIT and GSHUTDOWN, but
rather use the passed pointers directly.  For simplicity, we inline
`php_oci_cleanup_global_handles()`, and also the `PHP_OCI_CALL()`
macros; the latter are unlikely to be needed here, but don't hurt.

Closes GH-7766.
  • Loading branch information
cmb69 committed Dec 12, 2021
1 parent 9998082 commit c435e67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ PHP NEWS
. Fixed bug GH-7759 (Incorrect return types for hash() and hash_hmac()).
(cmb)

- OCI8:
. Fixed bug GH-7765 (php_oci_cleanup_global_handles segfaults at second
call). (cmb)

- PDO_PGSQL:
. Fixed error message allocation of PDO PgSQL. (SATO Kentaro)

Expand Down
33 changes: 14 additions & 19 deletions ext/oci8/oci8.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,6 @@ static void php_oci_init_global_handles(void)
}
/* }}} */

/* {{{ php_oci_cleanup_global_handles()
*
* Free global handles (if they were initialized before)
*/
static void php_oci_cleanup_global_handles(void)
{
if (OCI_G(err)) {
PHP_OCI_CALL(OCIHandleFree, ((dvoid *) OCI_G(err), OCI_HTYPE_ERROR));
OCI_G(err) = NULL;
}

if (OCI_G(env)) {
PHP_OCI_CALL(OCIHandleFree, ((dvoid *) OCI_G(env), OCI_HTYPE_ENV));
OCI_G(env) = NULL;
}
}
/* }}} */

/* {{{ PHP_GINIT_FUNCTION
*
* Zerofill globals during module init
Expand All @@ -270,10 +252,23 @@ static PHP_GINIT_FUNCTION(oci)
/* {{{ PHP_GSHUTDOWN_FUNCTION
*
* Called for thread shutdown in ZTS, after module shutdown for non-ZTS
* Free global handles (if they were initialized before)
*/
static PHP_GSHUTDOWN_FUNCTION(oci)
{
php_oci_cleanup_global_handles();
if (oci_globals->err) {
oci_globals->in_call = 1;
OCIHandleFree((dvoid *) oci_globals->err, OCI_HTYPE_ERROR);
oci_globals->in_call = 0;
oci_globals->err = NULL;
}

if (oci_globals->env) {
oci_globals->in_call = 1;
OCIHandleFree((dvoid *) oci_globals->env, OCI_HTYPE_ENV);
oci_globals->in_call = 0;
oci_globals->env = NULL;
}
}
/* }}} */

Expand Down

1 comment on commit c435e67

@cjbj
Copy link
Contributor

@cjbj cjbj commented on c435e67 Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

News to me! Thanks @cmb69

Please sign in to comment.