Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 184f274e authored by Tim Van Patten's avatar Tim Van Patten
Browse files

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
parent 03ec059e
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -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()));
            }
        }