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

Commit 5a8c69f8 authored by Andrei Homescu's avatar Andrei Homescu
Browse files

libbinder: Return error instead of crashing on closed Trusty connection

If RpcServerTrusty rejects a client connection, it still receives
a few more messages. Since the connection was rejected, the internal
channel has not been initialized. Handle this corner case by returning
an ERR_BAD_STATE error code instead of a fatal crash so that Trusty
services do not crash after rejecting connections.

Bug: 242940548
Test: Presubmit
Change-Id: Ibb1445c26616a8c7e369d1fd7a3fb3602d6f2155
parent be48640e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -151,8 +151,10 @@ int RpcServerTrusty::handleMessage(const tipc_port* /*port*/, handle_t /*chan*/,

int RpcServerTrusty::handleMessageInternal(void* ctx) {
    auto* channelContext = reinterpret_cast<ChannelContext*>(ctx);
    LOG_ALWAYS_FATAL_IF(channelContext == nullptr,
                        "bad state: message received on uninitialized channel");
    if (channelContext == nullptr) {
        LOG_RPC_DETAIL("bad state: message received on uninitialized channel");
        return ERR_BAD_STATE;
    }

    auto& session = channelContext->session;
    auto& connection = channelContext->connection;