From 47f2140d81528bf9c94381aa6708cc6bd1d86cfa Mon Sep 17 00:00:00 2001 From: yanhui Date: Sun, 27 Apr 2025 12:54:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8B=B7=E8=B4=9D=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E6=97=B6=E9=95=BF=E5=BA=A6=E7=BC=BA1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yanhui Change-Id: I12c7fdb608180a010fb2896d55d9d9dc64e793e4 Signed-off-by: yanhui --- .../src/session_manager/route_head_handler_impl.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index d7feaea8e..f8063b9c5 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -197,19 +197,22 @@ bool RouteHeadHandlerImpl::PackDataBody(uint8_t *data, uint32_t totalLen) SessionAppId *appPair = reinterpret_cast(ptr); uint32_t appIdSize = session_.appId.size(); appPair->len = HostToNet(appIdSize); - ret = strcpy_s(appPair->appId, appIdSize, session_.appId.c_str()); + uint8_t *end = data + totalLen; + ptr += sizeof(SessionAppId); + ret = memcpy_s(appPair->appId, end - ptr, session_.appId.c_str(), appIdSize); if (ret != 0) { - ZLOGE("strcpy for app id failed, error:%{public}d", errno); + ZLOGE("memcpy for app id failed, ret is %{public}d, leftSize is %{public}d, appIdSize is %{public}d", + ret, end - ptr, appIdSize); return false; } - ptr += (sizeof(SessionAppId) + appIdSize); + ptr += appIdSize; - uint8_t *end = data + totalLen; SessionStoreId *storePair = reinterpret_cast(ptr); uint32_t storeIdSize = session_.storeId.size(); ret = memcpy_s(storePair->storeId, end - ptr, session_.storeId.data(), storeIdSize); if (ret != 0) { - ZLOGE("strcpy for store id failed, error:%{public}d", errno); + ZLOGE("memcpy for store id failed, ret is %{public}d, leftSize is %{public}d, storeIdSize is %{public}d", + ret, end - ptr, storeIdSize); return false; } storePair->len = HostToNet(storeIdSize); -- Gitee