]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix WaitEventSetWait() buffer overrun.
authorThomas Munro <tmunro@postgresql.org>
Thu, 12 Jan 2023 21:40:52 +0000 (10:40 +1300)
committerThomas Munro <tmunro@postgresql.org>
Thu, 12 Jan 2023 21:57:29 +0000 (10:57 +1300)
commit547e60b8317e3c351900c650988327b73cf7ae33
tree336eb4197a04ebdf60ea807369b62eab79894571
parent0d9221f1d251b956a33660bff1420140f8abebcb
Fix WaitEventSetWait() buffer overrun.

The WAIT_USE_EPOLL and WAIT_USE_KQUEUE implementations of
WaitEventSetWaitBlock() confused the size of their internal buffer with
the size of the caller's output buffer, and could ask the kernel for too
many events.  In fact the set of events retrieved from the kernel needs
to be able to fit in both buffers, so take the smaller of the two.

The WAIT_USE_POLL and WAIT_USE WIN32 implementations didn't have this
confusion.

This probably didn't come up before because we always used the same
number in both places, but commit 7389aad6 calculates a dynamic size at
construction time, while using MAXLISTEN for its output event buffer on
the stack.  That seems like a reasonable thing to want to do, so
consider this to be a pre-existing bug worth fixing.

As discovered by valgrind on skink.

Back-patch to all supported releases for epoll, and to release 13 for
the kqueue part, which copied the incorrect epoll code.

Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/901504.1673504836%40sss.pgh.pa.us
src/backend/storage/ipc/latch.c