Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9089287

Browse files
committed
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
1 parent 29a0ccb commit 9089287

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/backend/utils/cache/plancache.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,9 @@ CachedPlanIsSimplyValid(CachedPlanSource *plansource, CachedPlan *plan,
14401440
* that here we *do* check plansource->is_valid, so as to force plan
14411441
* rebuild if that's become false.
14421442
*/
1443-
if (!plansource->is_valid || plan != plansource->gplan || !plan->is_valid)
1443+
if (!plansource->is_valid ||
1444+
plan == NULL || plan != plansource->gplan ||
1445+
!plan->is_valid)
14441446
return false;
14451447

14461448
Assert(plan->magic == CACHEDPLAN_MAGIC);

0 commit comments

Comments
 (0)