Skip to content

Commit 184f274

Browse files
committed
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
1 parent 03ec059 commit 184f274

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

opengl/libs/EGL/egl_display.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn
134134

135135
if (cnx->egl.eglGetPlatformDisplay) {
136136
std::vector<EGLAttrib> attrs;
137+
// These must have the same lifetime as |attrs|, because |attrs| contains pointers to these
138+
// variables.
139+
std::vector<const char*> enabled; // ANGLE features to enable
140+
std::vector<const char*> disabled; // ANGLE features to disable
141+
137142
if (attrib_list) {
138143
for (const EGLAttrib* attr = attrib_list; *attr != EGL_NONE; attr += 2) {
139144
attrs.push_back(attr[0]);
@@ -142,9 +147,6 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn
142147
}
143148

144149
if (graphicsenv_flags::feature_overrides()) {
145-
std::vector<const char*> enabled; // ANGLE features to enable
146-
std::vector<const char*> disabled; // ANGLE features to disable
147-
148150
// Get the list of ANGLE features to enable from Global.Settings.
149151
const auto& eglFeatures = GraphicsEnv::getInstance().getAngleEglFeatures();
150152
for (const std::string& eglFeature : eglFeatures) {
@@ -154,25 +156,24 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn
154156
// Get the list of ANGLE features to enable/disable from gpuservice.
155157
GraphicsEnv::getInstance().getAngleFeatureOverrides(enabled, disabled);
156158
if (!enabled.empty()) {
157-
enabled.push_back(0);
159+
enabled.push_back(nullptr);
158160
attrs.push_back(EGL_FEATURE_OVERRIDES_ENABLED_ANGLE);
159161
attrs.push_back(reinterpret_cast<EGLAttrib>(enabled.data()));
160162
}
161163
if (!disabled.empty()) {
162-
disabled.push_back(0);
164+
disabled.push_back(nullptr);
163165
attrs.push_back(EGL_FEATURE_OVERRIDES_DISABLED_ANGLE);
164166
attrs.push_back(reinterpret_cast<EGLAttrib>(disabled.data()));
165167
}
166168
} else {
167169
const auto& eglFeatures = GraphicsEnv::getInstance().getAngleEglFeatures();
168-
std::vector<const char*> features;
169-
if (eglFeatures.size() > 0) {
170+
if (!eglFeatures.empty()) {
170171
for (const std::string& eglFeature : eglFeatures) {
171-
features.push_back(eglFeature.c_str());
172+
enabled.push_back(eglFeature.c_str());
172173
}
173-
features.push_back(0);
174+
enabled.push_back(nullptr);
174175
attrs.push_back(EGL_FEATURE_OVERRIDES_ENABLED_ANGLE);
175-
attrs.push_back(reinterpret_cast<EGLAttrib>(features.data()));
176+
attrs.push_back(reinterpret_cast<EGLAttrib>(enabled.data()));
176177
}
177178
}
178179

0 commit comments

Comments
 (0)