pgsql: Fix cross variable references in graph pattern causing segfault

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix cross variable references in graph pattern causing segfault
Date: 2026-03-31 09:53:08
Message-ID: E1w7VmV-002I3X-0h@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix cross variable references in graph pattern causing segfault

When converting the WHERE clause in an element pattern,
generate_query_for_graph_path() calls replace_property_refs() to
replace the property references in it. Only the current graph element
pattern is passed as the context for replacement. If there are
references to variables from other element patterns, it causes a
segmentation fault (an assertion failure in an Assert enabled build)
since it does not find path_element object corresponding to those
variables.

We do not support forward and backward variable references within a
graph table clause. Hence prohibit all the cross references.

Author: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Reported-by: Man Zeng <zengman(at)halodbtech(dot)com>
Reviewed-by: Henson Choi <assam258(at)gmail(dot)com>
Reviewed-by: Junwang Zhao <zhjwpku(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/CAExHW5u6AoDfNg4%3DR5eVJn_bJn%3DC%3DwVPrto02P_06fxy39fniA%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a0dd0702e464f206b08c99a74cb58809c51aafa5

Modified Files
--------------
src/backend/parser/parse_graphtable.c | 43 ++++++++++++++++++++++++++++---
src/include/parser/parse_node.h | 3 +++
src/test/regress/expected/graph_table.out | 20 ++++++++++++++
src/test/regress/sql/graph_table.sql | 8 ++++++
4 files changed, 71 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Christoph Berg 2026-03-31 10:18:49 Re: pgsql: test_aio: Add basic tests for StartReadBuffers()
Previous Message Amit Langote 2026-03-31 08:08:41 Re: pgsql: Add fast path for foreign key constraint checks