diff options
author | 2025-02-06 09:33:15 -0700 | |
---|---|---|
committer | 2025-02-06 09:33:15 -0700 | |
commit | 184f274e4608f11616a93389d4ffefb91925c6d7 (patch) | |
tree | 41fa248fe4d2bc55bed0dd2c3caab3a5fbdb8461 /opengl | |
parent | 03ec059e19d131dc3ea20504f7c0372eddb26d91 (diff) |
getPlatformDisplayAngle: Fix std::vector scope error
The std::vector<const char*> variables were scoped to only within the
conditional blocks for graphicsenv_flags::feature_overrides(). However,
pointers to those vectors were added to the std::vector<EGLAttrib> attrs
which is passed to eglGetPlatformDisplay(), leading to a use-after-free
and ANGLE crashing due to a SIGSEGV.
Move the declarations of enabled/disabled std::vectors next to attrs so
their lifetimes match. Also, add a comment about why they are declared
there, so they aren't erroneously moved back inside the conditional
blocks where they are used in the future.
Bug: 372694741
Test: CQ, Manual verification
Flag: com.android.graphics.graphicsenv.flags.feature_overrides
Change-Id: I85a361819e082bc546933e2839e3741a6b4c4ffd
Diffstat (limited to 'opengl')
-rw-r--r-- | opengl/libs/EGL/egl_display.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp index 5fe948478b..0dd9f198e5 100644 --- a/opengl/libs/EGL/egl_display.cpp +++ b/opengl/libs/EGL/egl_display.cpp @@ -134,6 +134,11 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn if (cnx->egl.eglGetPlatformDisplay) { std::vector<EGLAttrib> attrs; + // These must have the same lifetime as |attrs|, because |attrs| contains pointers to these + // variables. + std::vector<const char*> enabled; // ANGLE features to enable + std::vector<const char*> disabled; // ANGLE features to disable + if (attrib_list) { for (const EGLAttrib* attr = attrib_list; *attr != EGL_NONE; attr += 2) { attrs.push_back(attr[0]); @@ -142,9 +147,6 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn } if (graphicsenv_flags::feature_overrides()) { - std::vector<const char*> enabled; // ANGLE features to enable - std::vector<const char*> disabled; // ANGLE features to disable - // Get the list of ANGLE features to enable from Global.Settings. const auto& eglFeatures = GraphicsEnv::getInstance().getAngleEglFeatures(); for (const std::string& eglFeature : eglFeatures) { @@ -154,25 +156,24 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn // Get the list of ANGLE features to enable/disable from gpuservice. GraphicsEnv::getInstance().getAngleFeatureOverrides(enabled, disabled); if (!enabled.empty()) { - enabled.push_back(0); + enabled.push_back(nullptr); attrs.push_back(EGL_FEATURE_OVERRIDES_ENABLED_ANGLE); attrs.push_back(reinterpret_cast<EGLAttrib>(enabled.data())); } if (!disabled.empty()) { - disabled.push_back(0); + disabled.push_back(nullptr); attrs.push_back(EGL_FEATURE_OVERRIDES_DISABLED_ANGLE); attrs.push_back(reinterpret_cast<EGLAttrib>(disabled.data())); } } else { const auto& eglFeatures = GraphicsEnv::getInstance().getAngleEglFeatures(); - std::vector<const char*> features; - if (eglFeatures.size() > 0) { + if (!eglFeatures.empty()) { for (const std::string& eglFeature : eglFeatures) { - features.push_back(eglFeature.c_str()); + enabled.push_back(eglFeature.c_str()); } - features.push_back(0); + enabled.push_back(nullptr); attrs.push_back(EGL_FEATURE_OVERRIDES_ENABLED_ANGLE); - attrs.push_back(reinterpret_cast<EGLAttrib>(features.data())); + attrs.push_back(reinterpret_cast<EGLAttrib>(enabled.data())); } } |