Guard against null plan pointer in CachedPlanIsSimplyValid().
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 20 Jul 2023 18:23:46 +0000 (14:23 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 20 Jul 2023 18:23:46 +0000 (14:23 -0400)
commit10fd061bbc66351bb9cdfc20b65d0c928620e21c
tree5790df8804144e58874bd9b7b7ab76797b6bc306
parent8286b432c32dbec8b3109c5b09a902adb2385c52
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
src/backend/utils/cache/plancache.c