Skip to content

Commit bb8d667

Browse files
authored
Fix GH-15102: ext/pgsql use after free on persistent connection renewal. (#15115)
simplifying the workflow by just using PQreset which force a new connection internally, connection process ids ought to be different, and let the existing checks do the rest.
1 parent 6e57550 commit bb8d667

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

ext/pgsql/pgsql.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
682682

683683
/* try to find if we already have this link in our persistent list */
684684
if ((le = zend_hash_find_ptr(&EG(persistent_list), str.s)) == NULL) { /* we don't */
685-
newpconn:
686685
if (PGG(max_links) != -1 && PGG(num_links) >= PGG(max_links)) {
687686
php_error_docref(NULL, E_WARNING,
688687
"Cannot create new link. Too many open links (" ZEND_LONG_FMT ")", PGG(num_links));
@@ -720,11 +719,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
720719
while ((pg_result = PQgetResult(le->ptr))) {
721720
PQclear(pg_result);
722721
}
723-
PQfinish(le->ptr);
724-
le->ptr = NULL;
725-
PGG(num_links)--;
726-
PGG(num_persistent)--;
727-
goto newpconn;
722+
PQreset(le->ptr);
728723
}
729724
/* ensure that the link did not die */
730725
if (PGG(auto_reset_persistent) & 1) {

0 commit comments

Comments
 (0)