From 8b7c9b63aefd383b1d088a29b8f89c4781253aa4 Mon Sep 17 00:00:00 2001 From: Haruka Takatsuka Date: Tue, 2 Jul 2024 13:21:42 +0900 Subject: [PATCH] Add a null-check for stored plan text in pg_store_plans_internal(). Variable pstr retrieved from function ptext_fetch() can be NULL due to various factors. Previously, pstr was passed as-is to each per-format process and used in strlen(), causing a crash when it was NULL. --- pg_store_plans.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pg_store_plans.c b/pg_store_plans.c index a8f01ca..f60b67b 100644 --- a/pg_store_plans.c +++ b/pg_store_plans.c @@ -1579,6 +1579,12 @@ pg_store_plans_internal(FunctionCallInfo fcinfo, else pstr = SHMEM_PLAN_PTR(entry); + if (pstr == NULL) + { + values[i++] = CStringGetTextDatum(""); + goto outofblock01; + } + switch (plan_format) { case PLAN_FORMAT_TEXT: @@ -1612,10 +1618,13 @@ pg_store_plans_internal(FunctionCallInfo fcinfo, pfree(mstr); /* pstr is a pointer onto pbuffer */ + } else values[i++] = CStringGetTextDatum(""); + outofblock01: + /* copy counters to a local variable to keep locking time short */ { volatile pgspEntry *e = (volatile pgspEntry *) entry;