From feb6fbad71a4a8bb5f3cc5e313de0e3ceb473759 Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Fri, 8 Nov 2024 15:20:31 +0800 Subject: [PATCH] add ValidateReadData to ReadCString Issue: https://gitee.com/openharmony/commonlibrary_c_utils/issues/IB2ZML?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