From 9d9eb81d94075181c360d4712b9fd3baa58d5782 Mon Sep 17 00:00:00 2001 From: Peter Lohrmann Date: Fri, 12 Jul 2013 16:15:25 -0400 Subject: [PATCH] trace: Protect against uninitialized pointers if debug extensions are not exposed by the underlying driver and the user is attempting to query for a message log or object label. Sets the return parameters to NULL --- dispatch/glproc.py | 24 ++++++++++++++++++++++++ wrappers/gltrace.py | 9 +++++++++ 2 files changed, 33 insertions(+) diff --git a/dispatch/glproc.py b/dispatch/glproc.py index 488f912..ea1667a 100644 --- a/dispatch/glproc.py +++ b/dispatch/glproc.py @@ -506,6 +506,30 @@ void * _getPrivateProcAddress(const char *procName); def isFunctionPublic(self, module, function): return function.name in public_symbols or function.name.startswith('CGL') + def failFunction(self, function): + # We fake this when they are not available + if function.name in ('glGetObjectLabel', 'glGetObjectPtrLabel'): + print r' if (length != 0) *length = 0;' + print r' if (label != 0 && bufSize > 0) *label = 0;' + return + if function.name in ('glGetDebugMessageLog', 'glGetDebugMessageLogARB'): + print r' if (sources != 0) *sources = 0;' + print r' if (types != 0) *types = 0;' + print r' if (ids != 0) *ids = 0;' + print r' if (severities != 0) *severities = 0;' + print r' if (lengths != 0) *lengths = 0;' + print r' if (messageLog != 0 && bufsize > 0) *messageLog = 0;' + return + if function.name in ('glGetDebugMessageLogAMD'): + print r' if (categories != 0) *categories = 0;' + print r' if (ids != 0) *ids = 0;' + print r' if (severities != 0) *severities = 0;' + print r' if (lengths != 0) *lengths = 0;' + print r' if (message != 0 && bufsize > 0) *message = 0;' + return + + Dispatcher.failFunction(self, function) + if __name__ == '__main__': print diff --git a/wrappers/gltrace.py b/wrappers/gltrace.py index 7bf2a35..63ddf9d 100644 --- a/wrappers/gltrace.py +++ b/wrappers/gltrace.py @@ -757,6 +757,15 @@ class GlTracer(Tracer): if function.name in self.marker_functions: return + # We may be faking KHR_debug, so ensure the pointer queries result is + # always zeroed to prevent dereference of unitialized pointers + if function.name == 'glGetPointerv': + print ' if (params &&' + print ' (pname == GL_DEBUG_CALLBACK_FUNCTION ||' + print ' pname == GL_DEBUG_CALLBACK_USER_PARAM)) {' + print ' *params = NULL;' + print ' }' + if function.name in self.getProcAddressFunctionNames: else_ = '' for marker_function in self.marker_functions: -- 2.43.0