From 9c3ed120162f9b8da6798fcba3e23a5de9ef984a Mon Sep 17 00:00:00 2001 From: chenchong_666 Date: Thu, 21 Dec 2023 15:38:43 +0800 Subject: [PATCH] fix:Ensure that the read and write addresses of the data are legal Signed-off-by: chenchong_666 --- ipc/native/src/mock/source/hitrace_invoker.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ipc/native/src/mock/source/hitrace_invoker.cpp b/ipc/native/src/mock/source/hitrace_invoker.cpp index 9b379665..dddd6dc5 100644 --- a/ipc/native/src/mock/source/hitrace_invoker.cpp +++ b/ipc/native/src/mock/source/hitrace_invoker.cpp @@ -109,10 +109,14 @@ bool HitraceInvoker::TraceServerReceieve(uint64_t handle, uint32_t code, Parcel if (isServerTraced) { size_t oldReadPosition = data.GetReadPosition(); // padded size(4 bytes) of uint8_t + if (data.GetDataSize() < PADDED_SIZE_OF_PARCEL) { + ZLOGE(TRACE_LABEL, "The size of the data packet is less than 4"); + return false; + } data.RewindRead(data.GetDataSize() - PADDED_SIZE_OF_PARCEL); // the padded size of traceid uint8_t idLen = data.ReadUint8(); - if (idLen >= sizeof(HiTraceIdStruct)) { + if ((idLen >= sizeof(HiTraceIdStruct)) && (idLen <= (data.GetDataSize() - PADDED_SIZE_OF_PARCEL))) { // padded size(4 bytes) of uint8_t data.RewindRead(data.GetDataSize() - PADDED_SIZE_OF_PARCEL - idLen); const uint8_t *idBytes = data.ReadUnpadBuffer(sizeof(HiTraceIdStruct)); -- Gitee