From 4ce212f2102ebb36b60a9ce030631704299a9b72 Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Tue, 19 May 2015 08:35:10 +0100 Subject: [PATCH] glxinfo: fix segfault when core profile is unavailable https://bugs.freedesktop.org/show_bug.cgi?id=85199 Signed-off-by: Julien Isorce --- src/xdemos/glinfo_common.c | 6 +++++- src/xdemos/glxinfo.c | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/xdemos/glinfo_common.c b/src/xdemos/glinfo_common.c index d3acc19..dace587 100644 --- a/src/xdemos/glinfo_common.c +++ b/src/xdemos/glinfo_common.c @@ -289,9 +289,13 @@ build_core_profile_extension_list(const struct ext_functions *extfuncs) totalLen = 0; for (i = 0; i < n; i++) { const char *ext = (const char *) extfuncs->GetStringi(GL_EXTENSIONS, i); - totalLen += strlen(ext) + 1; /* plus a space */ + if (ext) + totalLen += strlen(ext) + 1; /* plus a space */ } + if (!totalLen) + return NULL; + buffer = malloc(totalLen + 1); if (buffer) { int pos = 0; diff --git a/src/xdemos/glxinfo.c b/src/xdemos/glxinfo.c index c3e4ca3..8bd42d3 100644 --- a/src/xdemos/glxinfo.c +++ b/src/xdemos/glxinfo.c @@ -465,9 +465,9 @@ print_screen_info(Display *dpy, int scrnum, Bool allowDirect, const char *glVendor = (const char *) glGetString(GL_VENDOR); const char *glRenderer = (const char *) glGetString(GL_RENDERER); const char *glVersion = (const char *) glGetString(GL_VERSION); - char *glExtensions; - int glxVersionMajor; - int glxVersionMinor; + char *glExtensions = NULL; + int glxVersionMajor = 0; + int glxVersionMinor = 0; char *displayName = NULL; char *colon = NULL, *period = NULL; struct ext_functions extfuncs; @@ -482,21 +482,21 @@ print_screen_info(Display *dpy, int scrnum, Bool allowDirect, extfuncs.GetConvolutionParameteriv = (GETCONVOLUTIONPARAMETERIVPROC) glXGetProcAddressARB((GLubyte *) "glGetConvolutionParameteriv"); + if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) { + fprintf(stderr, "Error: glXQueryVersion failed\n"); + exit(1); + } + /* Get list of GL extensions */ - if (coreProfile) { + if (coreProfile && extfuncs.GetStringi && glxVersionMajor >= 3) glExtensions = build_core_profile_extension_list(&extfuncs); - } - else { + if (!glExtensions) { + coreProfile = False; glExtensions = (char *) glGetString(GL_EXTENSIONS); } CheckError(__LINE__); - if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) { - fprintf(stderr, "Error: glXQueryVersion failed\n"); - exit(1); - } - if (!coreWorked) { /* Strip the screen number from the display name, if present. */ if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) { -- 1.9.5 (Apple Git-50.3)