CyberDem0n / bg_mon

Background worker for monitoring PostgreSQL
MIT License
66 stars 11 forks source link

Fix buffer overflow in get_pg_locks #20

Closed CyberDem0n closed 5 years ago

CyberDem0n commented 5 years ago

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

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.2%) to 87.916% when pulling 58b969be6fcbe937aea73e84f657d908fa372f0b on bugfix/buffer-overflow into c7b5e86dcf58b42670e8254e0ba408db210d8bea on master.

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.2%) to 87.916% when pulling 58b969be6fcbe937aea73e84f657d908fa372f0b on bugfix/buffer-overflow into c7b5e86dcf58b42670e8254e0ba408db210d8bea on master.