Skip to content

Commit 987a3a5

Browse files
MagicalTuxdevnexen
authored andcommitted
Fix phpGH-19484 i: potential use after free when using persistent pgsql connections.
By setting the notice processor to a no-op when a persistent connection is cleaned for future use. Close phpGH-19485
1 parent a3de2ce commit 987a3a5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug GH-19245 (Success error message on TLS stream accept failure).
1111
(Jakub Zelenka)
1212

13+
- PGSQL:
14+
. Fixed bug GH-19485 (potential use after free when using persistent pgsql
15+
connections). (Mark Karpeles)
16+
1317
- Standard:
1418
. Fixed bug GH-16649 (UAF during array_splice). (alexandre-daubois)
1519

ext/pgsql/pgsql.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ static void _close_pgsql_plink(zend_resource *rsrc)
328328

329329
static void _php_pgsql_notice_handler(void *l, const char *message)
330330
{
331+
if (l == NULL) {
332+
/* This connection does not currently have a valid context, ignore this notice */
333+
return;
334+
}
331335
if (PGG(ignore_notices)) {
332336
return;
333337
}
@@ -360,6 +364,11 @@ static int _rollback_transactions(zval *el)
360364

361365
link = (PGconn *) rsrc->ptr;
362366

367+
/* unset notice processor if we initially did set it */
368+
if (PQsetNoticeProcessor(link, NULL, NULL) == _php_pgsql_notice_handler) {
369+
PQsetNoticeProcessor(link, _php_pgsql_notice_handler, NULL);
370+
}
371+
363372
if (PQsetnonblocking(link, 0)) {
364373
php_error_docref("ref.pgsql", E_NOTICE, "Cannot set connection to blocking mode");
365374
return -1;

0 commit comments

Comments
 (0)