Skip to content

Commit 8dc9eda

Browse files
committed
Fix use-after-free in GetExtStatisticsName
ReleaseSysCache(htup) was called before NameStr(staForm->stxname) was read, returning a pointer into the already-released tuple buffer. Copy the name with pstrdup() first, then release the cache entry.
1 parent f00c2b4 commit 8dc9eda

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/backend/optimizer/util/plancat.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,10 @@ GetExtStatisticsName(Oid statOid)
16211621
elog(ERROR, "cache lookup failed for statistics object %u", statOid);
16221622

16231623
staForm = (Form_pg_statistic_ext) GETSTRUCT(htup);
1624+
/* Copy the name before releasing the cache entry. */
1625+
char *result = pstrdup(NameStr(staForm->stxname));
16241626
ReleaseSysCache(htup);
1625-
return NameStr(staForm->stxname);
1627+
return result;
16261628
}
16271629

16281630
/*

0 commit comments

Comments
 (0)