Demos (master): glxinfo: fix segfault when core profile is unavailable

Brian Paul brianp at kemper.freedesktop.org
Mon May 25 15:03:49 UTC 2015


Module: Demos
Branch: master
Commit: fca824431608101298ff0735db4c09954dcf64ab
URL:    http://cgit.freedesktop.org/mesa/demos/commit/?id=fca824431608101298ff0735db4c09954dcf64ab

Author: Julien Isorce <j.isorce at samsung.com>
Date:   Tue May 19 08:35:10 2015 +0100

glxinfo: fix segfault when core profile is unavailable

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=85199

Signed-off-by: Julien Isorce <j.isorce at samsung.com>
Reviewed-by: Brian Paul <brianp at vmware.com>

---

 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 6a360a3..5d865f3 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 0f28647..dc29bd9 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))) {




More information about the mesa-commit mailing list