aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-07-20 14:23:46 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2023-07-20 14:23:46 -0400
commitfbaf65cd65f4f0810dab9f2b3e840e68d8b959eb (patch)
treeb632e30519c7734ec2405349f41aaabfab8b4687 /src
parentbc9993a5497748ca333beac34a8446114bfacce7 (diff)
downloadpostgresql-fbaf65cd65f4f0810dab9f2b3e840e68d8b959eb.tar.gz
postgresql-fbaf65cd65f4f0810dab9f2b3e840e68d8b959eb.zip
Guard against null plan pointer in CachedPlanIsSimplyValid().
If both the passed-in plan pointer and plansource->gplan are NULL, CachedPlanIsSimplyValid would think that the plan pointer is possibly-valid and try to dereference it. For the one extant call site in plpgsql, this situation doesn't normally happen which is why we've not noticed. However, it appears to be possible if the previous use of the cached plan failed, as per report from Justin Pryzby. Add an extra check to prevent crashing. Back-patch to v13 where this code was added. Discussion: https://postgr.es/m/ZLlV+STFz1l/WhAQ@telsasoft.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/cache/plancache.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 21387fba9f1..81f23104a79 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -1440,7 +1440,9 @@ CachedPlanIsSimplyValid(CachedPlanSource *plansource, CachedPlan *plan,
* that here we *do* check plansource->is_valid, so as to force plan
* rebuild if that's become false.
*/
- if (!plansource->is_valid || plan != plansource->gplan || !plan->is_valid)
+ if (!plansource->is_valid ||
+ plan == NULL || plan != plansource->gplan ||
+ !plan->is_valid)
return false;
Assert(plan->magic == CACHEDPLAN_MAGIC);