From b9734c13f168ef0d487aa122e486ca9b6dd6aa59 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 7 Jul 2021 15:21:25 -0400 Subject: Fix crash in postgres_fdw for provably-empty remote UPDATE/DELETE. In 86dc90056, I'd written find_modifytable_subplan with the assumption that if the immediate child of a ModifyTable is a Result, it must be a projecting Result with a subplan. However, if the UPDATE or DELETE has a provably-constant-false WHERE clause, that's not so: we'll generate a dummy subplan with a childless Result. Add the missing null-check so we don't crash on such cases. Per report from Alexander Pyhalov. Discussion: https://postgr.es/m/b9a6f53549456b2f3e2fd150dcd79d72@postgrespro.ru --- contrib/postgres_fdw/postgres_fdw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'contrib/postgres_fdw/postgres_fdw.c') diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 5cf10402a20..f15c97ad7a4 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -2370,7 +2370,9 @@ find_modifytable_subplan(PlannerInfo *root, if (subplan_index < list_length(appendplan->appendplans)) subplan = (Plan *) list_nth(appendplan->appendplans, subplan_index); } - else if (IsA(subplan, Result) && IsA(outerPlan(subplan), Append)) + else if (IsA(subplan, Result) && + outerPlan(subplan) != NULL && + IsA(outerPlan(subplan), Append)) { Append *appendplan = (Append *) outerPlan(subplan); -- cgit v1.2.3