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

Commit 7635ebd8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "libbinder: Remove flexible array from RpcWireReply" am: c56d0ecb am: 66d083b8

parents 006efbee 66d083b8
Loading
Loading
Loading
Loading
+17 −12
Original line number Original line Diff line number Diff line
@@ -563,7 +563,7 @@ status_t RpcState::transactAddress(const sp<RpcSession::RpcConnection>& connecti
static void cleanup_reply_data(Parcel* p, const uint8_t* data, size_t dataSize,
static void cleanup_reply_data(Parcel* p, const uint8_t* data, size_t dataSize,
                               const binder_size_t* objects, size_t objectsCount) {
                               const binder_size_t* objects, size_t objectsCount) {
    (void)p;
    (void)p;
    delete[] const_cast<uint8_t*>(data - offsetof(RpcWireReply, data));
    delete[] const_cast<uint8_t*>(data);
    (void)dataSize;
    (void)dataSize;
    LOG_ALWAYS_FATAL_IF(objects != nullptr);
    LOG_ALWAYS_FATAL_IF(objects != nullptr);
    LOG_ALWAYS_FATAL_IF(objectsCount != 0, "%zu objects remaining", objectsCount);
    LOG_ALWAYS_FATAL_IF(objectsCount != 0, "%zu objects remaining", objectsCount);
@@ -585,25 +585,30 @@ status_t RpcState::waitForReply(const sp<RpcSession::RpcConnection>& connection,
            return status;
            return status;
    }
    }


    CommandData data(command.bodySize);
    if (!data.valid()) return NO_MEMORY;

    iovec iov{data.data(), command.bodySize};
    if (status_t status = rpcRec(connection, session, "reply body", &iov, 1); status != OK)
        return status;

    if (command.bodySize < sizeof(RpcWireReply)) {
    if (command.bodySize < sizeof(RpcWireReply)) {
        ALOGE("Expecting %zu but got %" PRId32 " bytes for RpcWireReply. Terminating!",
        ALOGE("Expecting %zu but got %" PRId32 " bytes for RpcWireReply. Terminating!",
              sizeof(RpcWireReply), command.bodySize);
              sizeof(RpcWireReply), command.bodySize);
        (void)session->shutdownAndWait(false);
        (void)session->shutdownAndWait(false);
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }
    RpcWireReply* rpcReply = reinterpret_cast<RpcWireReply*>(data.data());
    if (rpcReply->status != OK) return rpcReply->status;


    RpcWireReply rpcReply;
    CommandData data(command.bodySize - sizeof(RpcWireReply));
    if (!data.valid()) return NO_MEMORY;

    iovec iovs[]{
            {&rpcReply, sizeof(RpcWireReply)},
            {data.data(), data.size()},
    };
    if (status_t status = rpcRec(connection, session, "reply body", iovs, arraysize(iovs));
        status != OK)
        return status;
    if (rpcReply.status != OK) return rpcReply.status;

    uint8_t* parcelData = data.data();
    size_t parcelDataSize = data.size();
    data.release();
    data.release();
    reply->rpcSetDataReference(session, rpcReply->data,
    reply->rpcSetDataReference(session, parcelData, parcelDataSize, cleanup_reply_data);
                               command.bodySize - offsetof(RpcWireReply, data), cleanup_reply_data);


    return OK;
    return OK;
}
}
+0 −1
Original line number Original line Diff line number Diff line
@@ -139,7 +139,6 @@ static_assert(sizeof(RpcWireTransaction) == 40);


struct RpcWireReply {
struct RpcWireReply {
    int32_t status; // transact return
    int32_t status; // transact return
    uint8_t data[];
};
};
static_assert(sizeof(RpcWireReply) == 4);
static_assert(sizeof(RpcWireReply) == 4);


+9 −7
Original line number Original line Diff line number Diff line
@@ -203,13 +203,15 @@ TEST(RpcBinderAllocation, SetupRpcServer) {
    auto remoteBinder = session->getRootObject();
    auto remoteBinder = session->getRootObject();


    size_t mallocs = 0, totalBytes = 0;
    size_t mallocs = 0, totalBytes = 0;
    {
        const auto on_malloc = OnMalloc([&](size_t bytes) {
        const auto on_malloc = OnMalloc([&](size_t bytes) {
            mallocs++;
            mallocs++;
            totalBytes += bytes;
            totalBytes += bytes;
        });
        });
        CHECK_EQ(OK, remoteBinder->pingBinder());
        CHECK_EQ(OK, remoteBinder->pingBinder());
    EXPECT_EQ(mallocs, 3);
    }
    EXPECT_EQ(totalBytes, 60);
    EXPECT_EQ(mallocs, 2);
    EXPECT_EQ(totalBytes, 56);
}
}


int main(int argc, char** argv) {
int main(int argc, char** argv) {