Commit bbf1893c authored by Martin Roukala's avatar Martin Roukala Committed by Adam Jackson
Browse files

os: make sure the clientsWritable fd_set is initialized before use

In WaitForSomething(), the fd_set clientsWritable may be used
unitialized when the boolean AnyClientsWriteBlocked is set in the
WakeupHandler(). This leads to a crash in FlushAllOutput() after
x11proto's commit 2c94cdb453bc641246cc8b9a876da9799bee1ce7.

The problem did not manifest before because both the XFD_SIZE and the
maximum number of clients were set to 256. As the connectionTranslation
table was initalized for the 256 clients to 0, the test on the index not
being 0 was aborting before dereferencing the client #0.

As of commit 2c94cdb453bc641246cc8b9a876da9799bee1ce7 in x11proto, the
XFD_SIZE got bumped to 512. This lead the OutputPending fd_set to have
any fd above 256 to be uninitialized which in turns lead to reading an
index after the end of the ConnectionTranslation table. This index would
then be used to find the client corresponding to the fd marked as
pending writes and would also result to an out-of-bound access which
would usually be the fatal one.

Fix this by zeroing the clientsWritable fd_set at the beginning of
WaitForSomething(). In this case, the bottom part of the loop, which
would indirectly call FlushAllOutput, will not do any work but the next
call to select will result in the execution of the right codepath. This
is exactly what we want because we need to know the writable clients
before handling them. In the end, it also makes sure that the fds above
MaxClient are initialized, preventing the crash in FlushAllOutput().

Thanks to everyone involved in tracking this one down!
Reported-by: default avatarKarol Herbst <>
Reported-by: default avatarTobias Klausmann <>
Signed-off-by: Martin Roukala's avatarMartin Peres <>
Tested-by: default avatarTobias Klausmann <>
Tested-by: Martin Roukala's avatarMartin Peres <>

Cc: Ilia Mirkin  <>
Cc: Olivier Fourdan <
Cc: Adam Jackson <>
Cc: Alan Coopersmith <
Cc: Chris Wilson <>
Reviewed-by: Alan Coopersmith's avatarAlan Coopersmith <>
parent 6e389204
......@@ -158,6 +158,7 @@ WaitForSomething(int *pClientsReady)
Bool someReady = FALSE;
if (nready)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment