Fix off-by-one loop termination condition in pg_stat_get_subscription().
authorTom Lane <[email protected]>
Tue, 7 Jun 2022 19:34:30 +0000 (15:34 -0400)
committerTom Lane <[email protected]>
Tue, 7 Jun 2022 19:34:30 +0000 (15:34 -0400)
commitfb646cbd5a9e83441744160f89d6ba01f2f0bf8b
tree8272644210693ccb35671b1baee00ecdd764075b
parent89254606b61e36b82930c509326d46b72e003545
Fix off-by-one loop termination condition in pg_stat_get_subscription().

pg_stat_get_subscription scanned one more LogicalRepWorker array entry
than is really allocated.  In the worst case this could lead to SIGSEGV,
if the LogicalRepCtx data structure is near the end of shared memory.
That seems quite unlikely though (thanks to the ordering of calls in
CreateSharedMemoryAndSemaphores) and we've heard no field reports of it.
A more likely misbehavior is one row of garbage data in the function's
result, but even that is not real likely because of the check that the
pid field matches some live backend.

Report and fix by Kuntal Ghosh.  This bug is old, so back-patch
to all supported branches.

Discussion: https://postgr.es/m/CAGz5QCJykEDzW6jQK6Yz7Qh_PMtD=95de_7QoocbVR2Qy8hWZA@mail.gmail.com
src/backend/replication/logical/launcher.c