BackendIdGetTransactionIds() neglected the possibility that the PROC
pointer in a ProcState array entry is null. In current usage, this could
only crash if the other backend had exited since pgstat_read_current_status
saw it as active, which is a pretty narrow window. But it's reachable in
the field, per bug #12918 from Vladimir Borodin.
Back-patch to 9.4 where the faulty code was introduced.
void
BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmin)
{
- ProcState *stateP;
SISeg *segP = shmInvalBuffer;
- PGXACT *xact;
*xid = InvalidTransactionId;
*xmin = InvalidTransactionId;
if (backendID > 0 && backendID <= segP->lastBackend)
{
- stateP = &segP->procState[backendID - 1];
- xact = &ProcGlobal->allPgXact[stateP->proc->pgprocno];
+ ProcState *stateP = &segP->procState[backendID - 1];
+ PGPROC *proc = stateP->proc;
- *xid = xact->xid;
- *xmin = xact->xmin;
+ if (proc != NULL)
+ {
+ PGXACT *xact = &ProcGlobal->allPgXact[proc->pgprocno];
+
+ *xid = xact->xid;
+ *xmin = xact->xmin;
+ }
}
LWLockRelease(SInvalWriteLock);