Skip to content

Commit d7cdcc3

Browse files
committed
Fix phpGH-15102: use after free on persistent connection renewal.
simplifying the workflow by just using PQreset which renew internally the connection and let the existing checks do the rest, process id should still be different.
1 parent ab449a7 commit d7cdcc3

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

ext/pgsql/pgsql.c

Lines changed: 1 addition & 6 deletions
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)