summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-02 11:21:11 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-24 10:48:05 +0200
commit50d7bfe1dfa25621e25cccbc9b920669bb8464b3 (patch)
tree6b8b62eb8d46b4ad8de77febad957e4153bf0bed
parente8a352a6a7365110f6b3df5bef92ed576e354422 (diff)
Fix read-after-free on EGL extensions
Cache the read extensions as an std::string, since the returned C string may be not be permanent. Change-Id: I856b2b784ab4027da25996b2bf741b30cda10e05 Reviewed-by: Michal Klocek <michal.klocek@qt.io> (cherry picked from commit fd2fc0d2a86f39d563720563555ca6319f8ab223)
-rw-r--r--src/core/ozone/gl_surface_egl_qt.cpp6
-rw-r--r--src/core/ozone/gl_surface_glx_qt.cpp12
-rw-r--r--src/core/ozone/gl_surface_qt.cpp6
-rw-r--r--src/core/ozone/gl_surface_qt.h8
4 files changed, 16 insertions, 16 deletions
diff --git a/src/core/ozone/gl_surface_egl_qt.cpp b/src/core/ozone/gl_surface_egl_qt.cpp
index 849f0ee4d..a354c310b 100644
--- a/src/core/ozone/gl_surface_egl_qt.cpp
+++ b/src/core/ozone/gl_surface_egl_qt.cpp
@@ -95,7 +95,7 @@ bool GLSurfaceEGLQt::InitializeOneOff()
g_client_extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
g_extensions = eglQueryString(g_display, EGL_EXTENSIONS);
- g_egl_surfaceless_context_supported = ExtensionsContain(g_extensions, "EGL_KHR_surfaceless_context");
+ g_egl_surfaceless_context_supported = ExtensionsContain(g_extensions.c_str(), "EGL_KHR_surfaceless_context");
if (g_egl_surfaceless_context_supported) {
scoped_refptr<GLSurface> surface = new GLSurfacelessQtEGL(gfx::Size(1, 1));
gl::GLContextAttribs attribs;
@@ -209,12 +209,12 @@ void GLSurfaceEGL::ShutdownOneOff()
const char *GLSurfaceEGL::GetEGLClientExtensions()
{
- return GLSurfaceQt::g_client_extensions;
+ return GLSurfaceQt::g_client_extensions.c_str();
}
const char *GLSurfaceEGL::GetEGLExtensions()
{
- return GLSurfaceQt::g_extensions;
+ return GLSurfaceQt::g_extensions.c_str();
}
bool GLSurfaceEGL::HasEGLClientExtension(const char *name)
diff --git a/src/core/ozone/gl_surface_glx_qt.cpp b/src/core/ozone/gl_surface_glx_qt.cpp
index 5ccf5037a..79a084941 100644
--- a/src/core/ozone/gl_surface_glx_qt.cpp
+++ b/src/core/ozone/gl_surface_glx_qt.cpp
@@ -54,7 +54,7 @@ void GLSurfaceGLX::ShutdownOneOff()
bool GLSurfaceGLX::IsCreateContextSupported()
{
- return ExtensionsContain(GLSurfaceQt::g_extensions, "GLX_ARB_create_context");
+ return HasGLXExtension("GLX_ARB_create_context");
}
bool GLSurfaceGLX::IsCreateContextRobustnessSupported()
@@ -79,7 +79,7 @@ bool GLSurfaceGLX::IsCreateContextProfileSupported()
bool GLSurfaceGLX::IsCreateContextES2ProfileSupported()
{
- return ExtensionsContain(GLSurfaceQt::g_extensions, "GLX_ARB_create_context_es2_profile");
+ return HasGLXExtension("GLX_ARB_create_context_es2_profile");
}
bool GLSurfaceGLX::IsOMLSyncControlSupported()
@@ -89,12 +89,12 @@ bool GLSurfaceGLX::IsOMLSyncControlSupported()
bool GLSurfaceGLX::HasGLXExtension(const char *name)
{
- return ExtensionsContain(GLSurfaceQt::g_extensions, name);
+ return ExtensionsContain(GLSurfaceQt::g_extensions.c_str(), name);
}
bool GLSurfaceGLX::IsTextureFromPixmapSupported()
{
- return ExtensionsContain(GLSurfaceQt::g_extensions, "GLX_EXT_texture_from_pixmap");
+ return HasGLXExtension("GLX_EXT_texture_from_pixmap");
}
bool GLSurfaceGLX::IsRobustnessVideoMemoryPurgeSupported()
@@ -104,7 +104,7 @@ bool GLSurfaceGLX::IsRobustnessVideoMemoryPurgeSupported()
const char* GLSurfaceGLX::GetGLXExtensions()
{
- return GLSurfaceQt::g_extensions;
+ return GLSurfaceQt::g_extensions.c_str();
}
@@ -162,7 +162,7 @@ bool GLSurfaceGLXQt::InitializeExtensionSettingsOneOff()
Display* display = static_cast<Display*>(g_display);
GLSurfaceQt::g_extensions = glXQueryExtensionsString(display, 0);
- g_driver_glx.InitializeExtensionBindings(g_extensions);
+ g_driver_glx.InitializeExtensionBindings(g_extensions.c_str());
return true;
}
diff --git a/src/core/ozone/gl_surface_qt.cpp b/src/core/ozone/gl_surface_qt.cpp
index 8af3bd3c1..9bf16c960 100644
--- a/src/core/ozone/gl_surface_qt.cpp
+++ b/src/core/ozone/gl_surface_qt.cpp
@@ -64,8 +64,8 @@ namespace gl {
void *GLSurfaceQt::g_display = nullptr;
void *GLSurfaceQt::g_config = nullptr;
-const char *GLSurfaceQt::g_client_extensions = nullptr;
-const char *GLSurfaceQt::g_extensions = nullptr;
+std::string GLSurfaceQt::g_client_extensions;
+std::string GLSurfaceQt::g_extensions;
GLSurfaceQt::~GLSurfaceQt()
{
@@ -86,7 +86,7 @@ GLSurfaceQt::GLSurfaceQt(const gfx::Size& size)
bool GLSurfaceQt::HasEGLExtension(const char* name)
{
- return ExtensionsContain(g_extensions, name);
+ return ExtensionsContain(g_extensions.c_str(), name);
}
bool GLSurfaceQt::IsOffscreen()
diff --git a/src/core/ozone/gl_surface_qt.h b/src/core/ozone/gl_surface_qt.h
index 055b27875..8689c3a19 100644
--- a/src/core/ozone/gl_surface_qt.h
+++ b/src/core/ozone/gl_surface_qt.h
@@ -37,11 +37,11 @@
**
****************************************************************************/
-
-
#ifndef GL_SURFACE_QT_H_
#define GL_SURFACE_QT_H_
+#include <string>
+
#include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_surface.h"
@@ -71,8 +71,8 @@ protected:
public:
static void* g_config;
static void* g_display;
- static const char* g_extensions;
- static const char* g_client_extensions;
+ static std::string g_extensions;
+ static std::string g_client_extensions;
private:
DISALLOW_COPY_AND_ASSIGN(GLSurfaceQt);