glx: Fix SEGV due to dereferencing a NULL ptr from XCB-GLX.
authorHal Gentz <zegentzy@protonmail.com>
Thu, 25 Jul 2019 21:40:50 +0000 (15:40 -0600)
committerAdam Jackson <ajax@nwnk.net>
Wed, 4 Sep 2019 16:00:10 +0000 (16:00 +0000)
commit1591d1fee5016a21477edec0d2eb6b2d24221952
tree5fd2ba643972a55ffde9ae8fa2c94619ebcdc84e
parent9acb94b6236f8a76a5558cf1cb60bac976067851
glx: Fix SEGV due to dereferencing a NULL ptr from XCB-GLX.

When run in optirun, applications that linked to `libGLX.so` and then
proceeded to querying Mesa for extension strings caused a SEGV in Mesa.

`glXQueryExtensionsString` was calling a chain of functions that
eventually led to `__glXQueryServerString`. This function would call
`xcb_glx_query_server_string` then `xcb_glx_query_server_string_reply`.
The latter for some unknown reason returned `NULL`. Passing this `NULL`
to `xcb_glx_query_server_string_string_length` would cause a SEGV as the
function tried to dereference it.

The reason behind the function returning `NULL` is yet to be determined,
however, simply checking that the ptr is not `NULL` resolves this. A
similar check has been added to `__glXGetString` for completeness sake,
although not immediately necessary.

In addition to that, we stumbled into a similar problem in
`AllocAndFetchScreenConfigs` which tries to access the configs to free
them if `__glXQueryServerString` fails. This, of course, SEGVs, because the
configs are yet to have been allocated. Simply continuing past the configs
if their config ptrs are `NULL` resolves this. We also switch to `calloc`
to make sure that the config ptrs are `NULL` by default, and not some
uninitialized value.

Cc: mesa-stable@lists.freedesktop.org
Fixes: 24b8a8cfe821 "glx: implement __glXGetString, hide __glXGetStringFromServer"
Fixes: cb3610e37c4c "Import the GLX client side library, formerly from xc/lib/GL/glx. Build it "
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
src/glx/glx_query.c
src/glx/glxext.c