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

Commit b0dd1184 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: RpcSession check no shutdown trigger

If a pipe can't be created, this will fail. This error would result in
creating a session which can't be shutdown.

Bug: 185167543
Test: binderRpcTest
Change-Id: Id80da21cdc125783ea744c09fb864a5dc5771464
parent 1e4c2b81
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -86,8 +86,7 @@ bool RpcSession::addNullDebuggingClient() {
        return false;
    }

    addClientConnection(std::move(serverFd));
    return true;
    return addClientConnection(std::move(serverFd));
}

sp<IBinder> RpcSession::getRootObject() {
@@ -312,24 +311,25 @@ bool RpcSession::setupOneSocketClient(const RpcSocketAddress& addr, int32_t id)

        LOG_RPC_DETAIL("Socket at %s client with fd %d", addr.toString().c_str(), serverFd.get());

        addClientConnection(std::move(serverFd));
        return true;
        return addClientConnection(std::move(serverFd));
    }

    ALOGE("Ran out of retries to connect to %s", addr.toString().c_str());
    return false;
}

void RpcSession::addClientConnection(unique_fd fd) {
bool RpcSession::addClientConnection(unique_fd fd) {
    std::lock_guard<std::mutex> _l(mMutex);

    if (mShutdownTrigger == nullptr) {
        mShutdownTrigger = FdTrigger::make();
        if (mShutdownTrigger == nullptr) return false;
    }

    sp<RpcConnection> session = sp<RpcConnection>::make();
    session->fd = std::move(fd);
    mClientConnections.push_back(session);
    return true;
}

void RpcSession::setForServer(const wp<RpcServer>& server, int32_t sessionId,
+2 −1
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ private:

    /** This is not a pipe. */
    struct FdTrigger {
        /** Returns nullptr for error case */
        static std::unique_ptr<FdTrigger> make();

        /**
@@ -155,7 +156,7 @@ private:

    bool setupSocketClient(const RpcSocketAddress& address);
    bool setupOneSocketClient(const RpcSocketAddress& address, int32_t sessionId);
    void addClientConnection(base::unique_fd fd);
    bool addClientConnection(base::unique_fd fd);
    void setForServer(const wp<RpcServer>& server, int32_t sessionId,
                      const std::shared_ptr<FdTrigger>& shutdownTrigger);
    sp<RpcConnection> assignServerToThisThread(base::unique_fd fd);