From fca824431608101298ff0735db4c09954dcf64ab Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Tue, 19 May 2015 08:35:10 +0100 Subject: glxinfo: fix segfault when core profile is unavailable Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=85199 Signed-off-by: Julien Isorce Reviewed-by: Brian Paul --- 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 6a360a31..5d865f34 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 0f28647d..dc29bd9f 100644 --- a/src/xdemos/glxinfo.c +++ b/src/xdemos/glxinfo.c @@ -468,9 +468,9 @@ print_screen_info(Display *dpy, int scrnum, 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; @@ -485,21 +485,21 @@ print_screen_info(Display *dpy, int scrnum, 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))) { -- cgit v1.2.3