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

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

libbinder: RpcServer protocol version error

Return an error if you set an invalid protocol
version on an RpcServer.

Previously, this would cause errors later down
the line.

Bug: 278946301
Test: binderRpcTest
Change-Id: Id496f1d39b2a32ce775e585f7690ae59503dc3aa
parent 71ea90d3
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -123,8 +123,13 @@ size_t RpcServer::getMaxThreads() {
    return mMaxThreads;
}

void RpcServer::setProtocolVersion(uint32_t version) {
bool RpcServer::setProtocolVersion(uint32_t version) {
    if (!RpcState::validateProtocolVersion(version)) {
        return false;
    }

    mProtocolVersion = version;
    return true;
}

void RpcServer::setSupportedFileDescriptorTransportModes(
+1 −5
Original line number Diff line number Diff line
@@ -104,11 +104,7 @@ size_t RpcSession::getMaxOutgoingThreads() {
}

bool RpcSession::setProtocolVersionInternal(uint32_t version, bool checkStarted) {
    if (version >= RPC_WIRE_PROTOCOL_VERSION_NEXT &&
        version != RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL) {
        ALOGE("Cannot start RPC session with version %u which is unknown (current protocol version "
              "is %u).",
              version, RPC_WIRE_PROTOCOL_VERSION);
    if (!RpcState::validateProtocolVersion(version)) {
        return false;
    }

+12 −0
Original line number Diff line number Diff line
@@ -398,6 +398,18 @@ status_t RpcState::rpcRec(
    return OK;
}

bool RpcState::validateProtocolVersion(uint32_t version) {
    if (version >= RPC_WIRE_PROTOCOL_VERSION_NEXT &&
        version != RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL) {
        ALOGE("Cannot use RPC binder protocol version %u which is unknown (current protocol "
              "version "
              "is %u).",
              version, RPC_WIRE_PROTOCOL_VERSION);
        return false;
    }
    return true;
}

status_t RpcState::readNewSessionResponse(const sp<RpcSession::RpcConnection>& connection,
                                          const sp<RpcSession>& session, uint32_t* version) {
    RpcNewSessionResponse response;
+2 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ public:
    RpcState();
    ~RpcState();

    [[nodiscard]] static bool validateProtocolVersion(uint32_t version);

    [[nodiscard]] status_t readNewSessionResponse(const sp<RpcSession::RpcConnection>& connection,
                                                  const sp<RpcSession>& session, uint32_t* version);
    [[nodiscard]] status_t sendConnectionInit(const sp<RpcSession::RpcConnection>& connection,
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ public:
     * used. However, this can be used in order to prevent newer protocol
     * versions from ever being used. This is expected to be useful for testing.
     */
    void setProtocolVersion(uint32_t version);
    [[nodiscard]] bool setProtocolVersion(uint32_t version);

    /**
     * Set the supported transports for sending and receiving file descriptors.
Loading