pgsql: Fix use-after-free in COPY (ON_ERROR)

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix use-after-free in COPY (ON_ERROR)
Date: 2026-11-06 00:19:20
Message-ID: E1xP7fs-00000000Nwd-41an@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix use-after-free in COPY (ON_ERROR)

When ON_ERROR handled a soft error, some of the contents set for the
error context callback could remain set and pointing at areas that could
be reset, leading to some use-after-frees depending on the input data
provided through COPY.

These contents are now reset at the beginning of NextCopyFrom(), before
processing the next tuple.

SET_NULL is affected down to v19, IGNORE down to v17.

Author: Gowdham M <gowdham(dot)m(at)zohocorp(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Shihao Zhong <zhong950419(at)gmail(dot)com>
Discussion: https://postgr.es/m/1a181ff6be8.6d14feb261368.4036709598649280477@zohocorp.com
Backpatch-through: 17

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/23e2a332dd24c6b67f4a9bdbb3e0dbdb0a527156

Modified Files
--------------
src/backend/commands/copyfromparse.c | 4 ++++
src/test/regress/expected/copy2.out | 8 ++++++++
src/test/regress/sql/copy2.sql | 11 +++++++++++
3 files changed, 23 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Richard Guo 2026-11-06 00:39:32 pgsql: Fix mismatched PHVs for join alias Vars flattened more than once
Previous Message Masahiko Sawada 2026-11-06 00:17:10 pgsql: Stabilize 051_effective_wal_level.pl.