cmds: secure against possible nullptrs from EGL and GL
This commit is contained in:
parent
408b6efb1e
commit
3906c5fd4e
2 changed files with 21 additions and 7 deletions
|
|
@ -174,9 +174,18 @@ class SystemInformation {
|
||||||
auto display = s_egl.eglGetDisplay(0);
|
auto display = s_egl.eglGetDisplay(0);
|
||||||
if (display != EGL_NO_DISPLAY) {
|
if (display != EGL_NO_DISPLAY) {
|
||||||
s_egl.eglInitialize(display, nullptr, nullptr);
|
s_egl.eglInitialize(display, nullptr, nullptr);
|
||||||
graphics_info_.egl_vendor = s_egl.eglQueryString(display, EGL_VENDOR);
|
|
||||||
graphics_info_.egl_version = s_egl.eglQueryString(display, EGL_VERSION);
|
auto egl_safe_get_string = [](EGLint item) {
|
||||||
graphics_info_.egl_extensions = anbox::utils::string_split(s_egl.eglQueryString(display, EGL_EXTENSIONS), ' ');
|
auto str = s_gles2.glGetString(item);
|
||||||
|
if (!str)
|
||||||
|
return std::string("n/a");
|
||||||
|
return std::string(reinterpret_cast<const char*>(str));
|
||||||
|
};
|
||||||
|
|
||||||
|
graphics_info_.egl_vendor = egl_safe_get_string(EGL_VENDOR);
|
||||||
|
graphics_info_.egl_version = egl_safe_get_string(EGL_VERSION);
|
||||||
|
const auto egl_extensions = egl_safe_get_string(EGL_EXTENSIONS);
|
||||||
|
graphics_info_.egl_extensions = anbox::utils::string_split(egl_extensions, ' ');
|
||||||
|
|
||||||
GLint config_attribs[] = {EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
GLint config_attribs[] = {EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
|
||||||
|
|
@ -192,16 +201,17 @@ class SystemInformation {
|
||||||
// glGetString will return null below which we handle correctly.
|
// glGetString will return null below which we handle correctly.
|
||||||
s_egl.eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context);
|
s_egl.eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context);
|
||||||
|
|
||||||
auto safe_get_string = [](GLint item) {
|
auto gl_safe_get_string = [](GLint item) {
|
||||||
auto str = s_gles2.glGetString(item);
|
auto str = s_gles2.glGetString(item);
|
||||||
if (!str)
|
if (!str)
|
||||||
return std::string("n/a");
|
return std::string("n/a");
|
||||||
return std::string(reinterpret_cast<const char*>(str));
|
return std::string(reinterpret_cast<const char*>(str));
|
||||||
};
|
};
|
||||||
|
|
||||||
graphics_info_.gles2_vendor = safe_get_string(GL_VENDOR);
|
graphics_info_.gles2_vendor = gl_safe_get_string(GL_VENDOR);
|
||||||
graphics_info_.gles2_version = safe_get_string(GL_VERSION);
|
graphics_info_.gles2_version = gl_safe_get_string(GL_VERSION);
|
||||||
graphics_info_.gles2_extensions = anbox::utils::string_split(safe_get_string(GL_EXTENSIONS), ' ');
|
const auto gl_extensions = gl_safe_get_string(GL_EXTENSIONS);
|
||||||
|
graphics_info_.gles2_extensions = anbox::utils::string_split(gl_extensions, ' ');
|
||||||
|
|
||||||
s_egl.eglMakeCurrent(display, nullptr, nullptr, nullptr);
|
s_egl.eglMakeCurrent(display, nullptr, nullptr, nullptr);
|
||||||
s_egl.eglDestroyContext(display, context);
|
s_egl.eglDestroyContext(display, context);
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,9 @@ class GLExtensions {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool support(char const* ext) const {
|
bool support(char const* ext) const {
|
||||||
|
if (!ext)
|
||||||
|
throw std::invalid_argument("Invalid extension name");
|
||||||
|
|
||||||
char const* ext_ptr = extensions;
|
char const* ext_ptr = extensions;
|
||||||
size_t const len = strlen(ext);
|
size_t const len = strlen(ext);
|
||||||
while ((ext_ptr = strstr(ext_ptr, ext)) != nullptr) {
|
while ((ext_ptr = strstr(ext_ptr, ext)) != nullptr) {
|
||||||
|
|
@ -38,6 +41,7 @@ class GLExtensions {
|
||||||
break;
|
break;
|
||||||
ext_ptr += len;
|
ext_ptr += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ext_ptr != nullptr;
|
return ext_ptr != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue