From 34e84c0cd0b0752603aa0678410f59ef85abb62b Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Sat, 2 Nov 2024 19:56:05 +0800 Subject: [PATCH] add ValidateReadData for ReadCString Issue: https://gitee.com/openharmony/commonlibrary_c_utils/issues/IB1MW6?from=project-issue Signed-off-by: chenkeyu --- base/src/parcel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index 64fcfc8..7fd2604 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -1098,6 +1098,9 @@ const char *Parcel::ReadCString() const char* eos = reinterpret_cast(memchr(cstr, 0, avail)); if (eos != nullptr) { const size_t dataLength = eos - cstr; + if (!ValidateReadData(dataLength + 1)) { + return nullptr; + } readCursor_ += (dataLength + 1); SkipBytes(GetPadSize(dataLength + 1)); return cstr; -- Gitee