Every item returned by GetLockStatusData contains information about lock held mode (ExclusiveLock, AccessShareLock, RowExclusiveLock and so on).
pg_locks view reports all modes for the same object and pg_lock_status() was copied without a full understanding of how it supposed to work, what causes a buffer overflow.
In fact, we are not interested in all modes, but only about lock status. Taking into account that the given record can represent granted lock on a given object and at the same time it could be waiting for a more strict lock, we need to extend array size by 2.
In addition to above mentioned bugfix create a separate memory context for bg_mon itself and refactor a bit MemoryContextSwitchTo() calls
Coverage decreased (-0.2%) to 87.916% when pulling 58b969be6fcbe937aea73e84f657d908fa372f0b on bugfix/buffer-overflow into c7b5e86dcf58b42670e8254e0ba408db210d8bea on master.
Coverage decreased (-0.2%) to 87.916% when pulling 58b969be6fcbe937aea73e84f657d908fa372f0b on bugfix/buffer-overflow into c7b5e86dcf58b42670e8254e0ba408db210d8bea on master.
Every item returned by GetLockStatusData contains information about lock held mode (ExclusiveLock, AccessShareLock, RowExclusiveLock and so on). pg_locks view reports all modes for the same object and pg_lock_status() was copied without a full understanding of how it supposed to work, what causes a buffer overflow. In fact, we are not interested in all modes, but only about lock status. Taking into account that the given record can represent granted lock on a given object and at the same time it could be waiting for a more strict lock, we need to extend array size by 2.
In addition to above mentioned bugfix create a separate memory context for bg_mon itself and refactor a bit MemoryContextSwitchTo() calls