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

Commit 8d980f59 authored by Yi Jiang's avatar Yi Jiang
Browse files

Add null checks for background color layer

The bgColorLayer pointer is lack of necessary null check, which could
potentially cause null pointer dereference.

Also added some annotations for the nested if-else statements.

Flag: EXEMPT refactor
Bug: 414341229
Test: presubmit tests

Change-Id: Iaaeb289d8f23090ac62111a10545fca9cb8291cd
parent ef9f0459
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -221,7 +221,20 @@ void LayerLifecycleManager::applyTransactions(
            layer->merge(resolvedComposerState);

            if (layer->what & layer_state_t::eBackgroundColorChanged) {
                if (layer->bgColorLayerId == UNASSIGNED_LAYER_ID && layer->bgColor.a != 0) {
                RequestedLayerState* bgColorLayer = nullptr;
                if (layer->bgColorLayerId != UNASSIGNED_LAYER_ID) {
                    bgColorLayer = getLayerFromId(layer->bgColorLayerId);
                    if (bgColorLayer == nullptr) {
                        LLOG_ALWAYS_FATAL_WITH_TRACE_IF(!ignoreUnknownLayers,
                                                        "%s Background color layer with layerid=%d "
                                                        "not found",
                                                        __func__, layer->bgColorLayerId);
                        layer->bgColorLayerId = UNASSIGNED_LAYER_ID;
                    }
                }
                if (bgColorLayer == nullptr && layer->bgColor.a != 0) {
                    // Case 1: The background layer doesn't exist and the background color has a
                    // non-zero alpha. Create a background layer.
                    LayerCreationArgs
                            backgroundLayerArgs(LayerCreationArgs::getInternalLayerId(
                                                        LayerCreationArgs::sInternalSequence++),
@@ -241,13 +254,15 @@ void LayerLifecycleManager::applyTransactions(
                    backgroundLayer->dataspace = layer->bgColorDataspace;
                    layer->bgColorLayerId = backgroundLayer->id;
                    addLayers({std::move(newLayers)});
                } else if (layer->bgColorLayerId != UNASSIGNED_LAYER_ID && layer->bgColor.a == 0) {
                    RequestedLayerState* bgColorLayer = getLayerFromId(layer->bgColorLayerId);
                } else if (bgColorLayer != nullptr && layer->bgColor.a == 0) {
                    // Case 2: The background layer exists and the background color has a zero
                    // alpha (invisible). Destroy the background layer.
                    layer->bgColorLayerId = UNASSIGNED_LAYER_ID;
                    bgColorLayer->parentId = unlinkLayer(bgColorLayer->parentId, bgColorLayer->id);
                    onHandlesDestroyed({{bgColorLayer->id, bgColorLayer->debugName}});
                } else if (layer->bgColorLayerId != UNASSIGNED_LAYER_ID) {
                    RequestedLayerState* bgColorLayer = getLayerFromId(layer->bgColorLayerId);
                } else if (bgColorLayer != nullptr && layer->bgColor.a != 0) {
                    // Case 3: The background layer exists and the background color alpha might
                    // have changed. Update the background layer.
                    bgColorLayer->color = layer->bgColor;
                    bgColorLayer->dataspace = layer->bgColorDataspace;
                    bgColorLayer->what |= layer_state_t::eColorChanged |