Skip to content

Prevent buffer overflow in Windows _dbus_poll verbose logging

Gauthier Lamaison requested to merge Pyrrhvs/dbus:master into master

Hi,

First, I would like to thank you for your awesome work on DBus.

At Witbe we've been using DBus on Windows for a couple years now, and we're registering more and more micro services to DBus as our product evolves. Lately, I've encountered an issue with DBus on Windows, more specifically an assertion failure, that caused the daemon to stop working.

dbus-daemon[2148]: warning: File "c:\users\public\workspace\dbus\80\build\tmp\dbus-1.12.12\dbus\dbus-sysdeps-win.c" line 1357 should not have been reached: buffer overflow in _dbus_poll

I had a look at the failing assertion and realized that it was due to our growing number of DBus clients (and also to a bug on our side preventing the clients to unregister properly ;) ). Around 135 fds monitored in _dbus_poll, the static 2000 bytes stack buffer used to log pending operation for every socket would not be enough to store everything, causing a buffer overflow that could corrupt the stack. In order to prevent that, an assertion was added causing the program to stop.

You'll find in this MR a suggestion in order to fix this issue. The idea is to allocate the buffer on the heap once when _dbus_poll is called for the first time (using a static pointer), and to then extend this buffer when needed.

We've tested this patch on our failing environment and the results are looking good.

Let me know if you're have any question regarding this MR.

Edited by Simon McVittie

Merge request reports