| From: | Noah Misch <noah(at)leadboat(dot)com> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: dblink: Refuse to use a connection that a dblink call is already |
| Date: | 2026-11-09 14:22:06 |
| Message-ID: | E1xQQG6-000000003uR-3SGN@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
dblink: Refuse to use a connection that a dblink call is already using.
Previously, a dblink query that returned rows kept using its
connection after handing each row to the declared column type's input
function. That input function can run user-defined code (e.g., a
domain type with a CHECK constraint), so SQL can re-enter dblink while
an outer call is still reading results, and close the connection that
call is reading from. The close freed the connection object while the
outer call held a pointer to it, so the next libpq call read and wrote
freed memory.
dblink never had a rule about reentrancy. Calls that issued a new
query failed on their own, but by accident rather than by design:
libpq rejects a new query while one is in progress. It doesn't reject
reading a result, so a reentrant dblink_get_result() consumed a row
out of the outer query's single-row stream.
Fix this by marking a connection while a dblink call is materializing
a result from it, and refusing every other dblink call on that
connection until it's done.
Backpatch to all supported branches.
Reported-by: 안지용 <jfdg1y76(at)gmail(dot)com>
Reviewed-by: Jacob Champion <champion(dot)p(at)gmail(dot)com>
Reviewed-by: Greg Burd <greg(at)burd(dot)me>
Backpatch-through: 14
Security: CVE-2026-120147
Branch
------
REL_16_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/f0aa151863c614c843aac5730a81642732c3564a
Author: Masahiko Sawada <msawada(at)postgresql(dot)org>
Modified Files
--------------
contrib/dblink/dblink.c | 139 +++++++++++++++++++++++++++---
contrib/dblink/expected/dblink.out | 167 +++++++++++++++++++++++++++++++++++++
contrib/dblink/sql/dblink.sql | 83 ++++++++++++++++++
3 files changed, 377 insertions(+), 12 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Noah Misch | 2026-11-09 14:22:07 | pgsql: Expand ALTER TABLE related tests |
| Previous Message | Noah Misch | 2026-11-09 14:22:05 | pgsql: Fix potential buffer overrun in ts_rank_cd(). |