Loading libs/binder/Parcel.cpp +42 −30 Original line number Original line Diff line number Diff line Loading @@ -987,12 +987,22 @@ status_t Parcel::writeCString(const char* str) status_t Parcel::writeString8(const String8& str) status_t Parcel::writeString8(const String8& str) { { status_t err = writeInt32(str.bytes()); return writeString8(str.string(), str.size()); // only write string if its length is more than zero characters, } // as readString8 will only read if the length field is non-zero. // this is slightly different from how writeString16 works. status_t Parcel::writeString8(const char* str, size_t len) if (str.bytes() > 0 && err == NO_ERROR) { { err = write(str.string(), str.bytes()+1); if (str == nullptr) return writeInt32(-1); status_t err = writeInt32(len); if (err == NO_ERROR) { uint8_t* data = (uint8_t*)writeInplace(len+sizeof(char)); if (data) { memcpy(data, str, len); *reinterpret_cast<char*>(data+len) = 0; return NO_ERROR; } err = mError; } } return err; return err; } } Loading Loading @@ -1832,37 +1842,39 @@ const char* Parcel::readCString() const String8 Parcel::readString8() const String8 Parcel::readString8() const { { String8 retString; size_t len; status_t status = readString8(&retString); const char* str = readString8Inplace(&len); if (status != OK) { if (str) return String8(str, len); // We don't care about errors here, so just return an empty string. ALOGE("Reading a NULL string not supported here."); return String8(); return String8(); } } return retString; } status_t Parcel::readString8(String8* pArg) const status_t Parcel::readString8(String8* pArg) const { { int32_t size; size_t len; status_t status = readInt32(&size); const char* str = readString8Inplace(&len); if (status != OK) { if (str) { return status; pArg->setTo(str, len); } return 0; // watch for potential int overflow from size+1 } else { if (size < 0 || size >= INT32_MAX) { return BAD_VALUE; } // |writeString8| writes nothing for empty string. if (size == 0) { *pArg = String8(); *pArg = String8(); return OK; return UNEXPECTED_NULL; } } } const char* Parcel::readString8Inplace(size_t* outLen) const { int32_t size = readInt32(); // watch for potential int overflow from size+1 if (size >= 0 && size < INT32_MAX) { *outLen = size; const char* str = (const char*)readInplace(size+1); const char* str = (const char*)readInplace(size+1); if (str == nullptr) { if (str != nullptr) { return BAD_VALUE; return str; } } pArg->setTo(str, size); } return OK; *outLen = 0; return nullptr; } } String16 Parcel::readString16() const String16 Parcel::readString16() const Loading libs/binder/include/binder/Parcel.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -119,6 +119,7 @@ public: status_t writeDouble(double val); status_t writeDouble(double val); status_t writeCString(const char* str); status_t writeCString(const char* str); status_t writeString8(const String8& str); status_t writeString8(const String8& str); status_t writeString8(const char* str, size_t len); status_t writeString16(const String16& str); status_t writeString16(const String16& str); status_t writeString16(const std::unique_ptr<String16>& str); status_t writeString16(const std::unique_ptr<String16>& str); status_t writeString16(const char16_t* str, size_t len); status_t writeString16(const char16_t* str, size_t len); Loading Loading @@ -283,6 +284,7 @@ public: const char* readCString() const; const char* readCString() const; String8 readString8() const; String8 readString8() const; status_t readString8(String8* pArg) const; status_t readString8(String8* pArg) const; const char* readString8Inplace(size_t* outLen) const; String16 readString16() const; String16 readString16() const; status_t readString16(String16* pArg) const; status_t readString16(String16* pArg) const; status_t readString16(std::unique_ptr<String16>* pArg) const; status_t readString16(std::unique_ptr<String16>* pArg) const; Loading libs/vr/libpdx_uds/service_endpoint.cpp +3 −3 Original line number Original line Diff line number Diff line Loading @@ -535,13 +535,13 @@ Status<void> Endpoint::ReceiveMessageForChannel( *message = Message{info}; *message = Message{info}; auto* state = static_cast<MessageState*>(message->GetState()); auto* state = static_cast<MessageState*>(message->GetState()); state->request = std::move(request); state->request = std::move(request); if (request.send_len > 0 && !request.is_impulse) { if (state->request.send_len > 0 && !state->request.is_impulse) { state->request_data.resize(request.send_len); state->request_data.resize(state->request.send_len); status = ReceiveData(channel_fd, state->request_data.data(), status = ReceiveData(channel_fd, state->request_data.data(), state->request_data.size()); state->request_data.size()); } } if (status && request.is_impulse) if (status && state->request.is_impulse) status = ReenableEpollEvent(channel_fd); status = ReenableEpollEvent(channel_fd); if (!status) { if (!status) { Loading services/inputflinger/tests/InputReader_test.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -1748,7 +1748,8 @@ protected: virtual void SetUp() override { virtual void SetUp() override { mFakePolicy = new FakeInputReaderPolicy(); mFakePolicy = new FakeInputReaderPolicy(); mTestListener = new TestInputListener(50ms); mTestListener = new TestInputListener(2000ms /*eventHappenedTimeout*/, 30ms /*eventDidNotHappenTimeout*/); mReader = new InputReader(std::make_shared<EventHub>(), mFakePolicy, mTestListener); mReader = new InputReader(std::make_shared<EventHub>(), mFakePolicy, mTestListener); ASSERT_EQ(mReader->start(), OK); ASSERT_EQ(mReader->start(), OK); Loading services/inputflinger/tests/TestInputListener.cpp +10 −7 Original line number Original line Diff line number Diff line Loading @@ -23,7 +23,10 @@ namespace android { // --- TestInputListener --- // --- TestInputListener --- TestInputListener::TestInputListener(const std::chrono::milliseconds timeout) : mTimeout(timeout) {} TestInputListener::TestInputListener(std::chrono::milliseconds eventHappenedTimeout, std::chrono::milliseconds eventDidNotHappenTimeout) : mEventHappenedTimeout(eventHappenedTimeout), mEventDidNotHappenTimeout(eventDidNotHappenTimeout) {} TestInputListener::~TestInputListener() { } TestInputListener::~TestInputListener() { } Loading Loading @@ -86,9 +89,9 @@ void TestInputListener::assertCalled(NotifyArgsType* outEventArgs, std::string m std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); if (queue.empty()) { if (queue.empty()) { const bool eventReceived = mCondition.wait_for(lock, mTimeout, [&queue]() REQUIRES(mLock) { const bool eventReceived = return !queue.empty(); mCondition.wait_for(lock, mEventHappenedTimeout, }); [&queue]() REQUIRES(mLock) { return !queue.empty(); }); if (!eventReceived) { if (!eventReceived) { FAIL() << "Timed out waiting for event: " << message.c_str(); FAIL() << "Timed out waiting for event: " << message.c_str(); } } Loading @@ -105,9 +108,9 @@ void TestInputListener::assertNotCalled(std::string message) { base::ScopedLockAssertion assumeLocked(mLock); base::ScopedLockAssertion assumeLocked(mLock); std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); const bool eventReceived = mCondition.wait_for(lock, mTimeout, [&queue]() REQUIRES(mLock) { const bool eventReceived = return !queue.empty(); mCondition.wait_for(lock, mEventDidNotHappenTimeout, }); [&queue]() REQUIRES(mLock) { return !queue.empty(); }); if (eventReceived) { if (eventReceived) { FAIL() << "Unexpected event: " << message.c_str(); FAIL() << "Unexpected event: " << message.c_str(); } } Loading Loading
libs/binder/Parcel.cpp +42 −30 Original line number Original line Diff line number Diff line Loading @@ -987,12 +987,22 @@ status_t Parcel::writeCString(const char* str) status_t Parcel::writeString8(const String8& str) status_t Parcel::writeString8(const String8& str) { { status_t err = writeInt32(str.bytes()); return writeString8(str.string(), str.size()); // only write string if its length is more than zero characters, } // as readString8 will only read if the length field is non-zero. // this is slightly different from how writeString16 works. status_t Parcel::writeString8(const char* str, size_t len) if (str.bytes() > 0 && err == NO_ERROR) { { err = write(str.string(), str.bytes()+1); if (str == nullptr) return writeInt32(-1); status_t err = writeInt32(len); if (err == NO_ERROR) { uint8_t* data = (uint8_t*)writeInplace(len+sizeof(char)); if (data) { memcpy(data, str, len); *reinterpret_cast<char*>(data+len) = 0; return NO_ERROR; } err = mError; } } return err; return err; } } Loading Loading @@ -1832,37 +1842,39 @@ const char* Parcel::readCString() const String8 Parcel::readString8() const String8 Parcel::readString8() const { { String8 retString; size_t len; status_t status = readString8(&retString); const char* str = readString8Inplace(&len); if (status != OK) { if (str) return String8(str, len); // We don't care about errors here, so just return an empty string. ALOGE("Reading a NULL string not supported here."); return String8(); return String8(); } } return retString; } status_t Parcel::readString8(String8* pArg) const status_t Parcel::readString8(String8* pArg) const { { int32_t size; size_t len; status_t status = readInt32(&size); const char* str = readString8Inplace(&len); if (status != OK) { if (str) { return status; pArg->setTo(str, len); } return 0; // watch for potential int overflow from size+1 } else { if (size < 0 || size >= INT32_MAX) { return BAD_VALUE; } // |writeString8| writes nothing for empty string. if (size == 0) { *pArg = String8(); *pArg = String8(); return OK; return UNEXPECTED_NULL; } } } const char* Parcel::readString8Inplace(size_t* outLen) const { int32_t size = readInt32(); // watch for potential int overflow from size+1 if (size >= 0 && size < INT32_MAX) { *outLen = size; const char* str = (const char*)readInplace(size+1); const char* str = (const char*)readInplace(size+1); if (str == nullptr) { if (str != nullptr) { return BAD_VALUE; return str; } } pArg->setTo(str, size); } return OK; *outLen = 0; return nullptr; } } String16 Parcel::readString16() const String16 Parcel::readString16() const Loading
libs/binder/include/binder/Parcel.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -119,6 +119,7 @@ public: status_t writeDouble(double val); status_t writeDouble(double val); status_t writeCString(const char* str); status_t writeCString(const char* str); status_t writeString8(const String8& str); status_t writeString8(const String8& str); status_t writeString8(const char* str, size_t len); status_t writeString16(const String16& str); status_t writeString16(const String16& str); status_t writeString16(const std::unique_ptr<String16>& str); status_t writeString16(const std::unique_ptr<String16>& str); status_t writeString16(const char16_t* str, size_t len); status_t writeString16(const char16_t* str, size_t len); Loading Loading @@ -283,6 +284,7 @@ public: const char* readCString() const; const char* readCString() const; String8 readString8() const; String8 readString8() const; status_t readString8(String8* pArg) const; status_t readString8(String8* pArg) const; const char* readString8Inplace(size_t* outLen) const; String16 readString16() const; String16 readString16() const; status_t readString16(String16* pArg) const; status_t readString16(String16* pArg) const; status_t readString16(std::unique_ptr<String16>* pArg) const; status_t readString16(std::unique_ptr<String16>* pArg) const; Loading
libs/vr/libpdx_uds/service_endpoint.cpp +3 −3 Original line number Original line Diff line number Diff line Loading @@ -535,13 +535,13 @@ Status<void> Endpoint::ReceiveMessageForChannel( *message = Message{info}; *message = Message{info}; auto* state = static_cast<MessageState*>(message->GetState()); auto* state = static_cast<MessageState*>(message->GetState()); state->request = std::move(request); state->request = std::move(request); if (request.send_len > 0 && !request.is_impulse) { if (state->request.send_len > 0 && !state->request.is_impulse) { state->request_data.resize(request.send_len); state->request_data.resize(state->request.send_len); status = ReceiveData(channel_fd, state->request_data.data(), status = ReceiveData(channel_fd, state->request_data.data(), state->request_data.size()); state->request_data.size()); } } if (status && request.is_impulse) if (status && state->request.is_impulse) status = ReenableEpollEvent(channel_fd); status = ReenableEpollEvent(channel_fd); if (!status) { if (!status) { Loading
services/inputflinger/tests/InputReader_test.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -1748,7 +1748,8 @@ protected: virtual void SetUp() override { virtual void SetUp() override { mFakePolicy = new FakeInputReaderPolicy(); mFakePolicy = new FakeInputReaderPolicy(); mTestListener = new TestInputListener(50ms); mTestListener = new TestInputListener(2000ms /*eventHappenedTimeout*/, 30ms /*eventDidNotHappenTimeout*/); mReader = new InputReader(std::make_shared<EventHub>(), mFakePolicy, mTestListener); mReader = new InputReader(std::make_shared<EventHub>(), mFakePolicy, mTestListener); ASSERT_EQ(mReader->start(), OK); ASSERT_EQ(mReader->start(), OK); Loading
services/inputflinger/tests/TestInputListener.cpp +10 −7 Original line number Original line Diff line number Diff line Loading @@ -23,7 +23,10 @@ namespace android { // --- TestInputListener --- // --- TestInputListener --- TestInputListener::TestInputListener(const std::chrono::milliseconds timeout) : mTimeout(timeout) {} TestInputListener::TestInputListener(std::chrono::milliseconds eventHappenedTimeout, std::chrono::milliseconds eventDidNotHappenTimeout) : mEventHappenedTimeout(eventHappenedTimeout), mEventDidNotHappenTimeout(eventDidNotHappenTimeout) {} TestInputListener::~TestInputListener() { } TestInputListener::~TestInputListener() { } Loading Loading @@ -86,9 +89,9 @@ void TestInputListener::assertCalled(NotifyArgsType* outEventArgs, std::string m std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); if (queue.empty()) { if (queue.empty()) { const bool eventReceived = mCondition.wait_for(lock, mTimeout, [&queue]() REQUIRES(mLock) { const bool eventReceived = return !queue.empty(); mCondition.wait_for(lock, mEventHappenedTimeout, }); [&queue]() REQUIRES(mLock) { return !queue.empty(); }); if (!eventReceived) { if (!eventReceived) { FAIL() << "Timed out waiting for event: " << message.c_str(); FAIL() << "Timed out waiting for event: " << message.c_str(); } } Loading @@ -105,9 +108,9 @@ void TestInputListener::assertNotCalled(std::string message) { base::ScopedLockAssertion assumeLocked(mLock); base::ScopedLockAssertion assumeLocked(mLock); std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); const bool eventReceived = mCondition.wait_for(lock, mTimeout, [&queue]() REQUIRES(mLock) { const bool eventReceived = return !queue.empty(); mCondition.wait_for(lock, mEventDidNotHappenTimeout, }); [&queue]() REQUIRES(mLock) { return !queue.empty(); }); if (eventReceived) { if (eventReceived) { FAIL() << "Unexpected event: " << message.c_str(); FAIL() << "Unexpected event: " << message.c_str(); } } Loading