From d7c88780e1df54f34563d60bd7fa01011d2eef03 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期一, 26 一月 2026 23:17:17 +0800
Subject: [PATCH] 1.CSVData.cpp 里 unserialize 用了 8*2、125*2,但 serialize 只写 8 + 125 字节。 m_svRawData.insert 的 end 指针是 pszBuffer + 125*2,没有用 index 计算,可能把无效区域一起拷进去。 一旦 size 实际是 133(不是 266),就会直接越界,堆会被破坏,m_svDatas.clear() 在销毁元素时崩。
---
SourceCode/Bond/Servo/CRecipesManager.cpp | 185 ++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 171 insertions(+), 14 deletions(-)
diff --git a/SourceCode/Bond/Servo/CRecipesManager.cpp b/SourceCode/Bond/Servo/CRecipesManager.cpp
index 34bac63..98a17a2 100644
--- a/SourceCode/Bond/Servo/CRecipesManager.cpp
+++ b/SourceCode/Bond/Servo/CRecipesManager.cpp
@@ -15,10 +15,12 @@
{
m_nSyncStatus = SS_NONE;
m_nTotalMasterRecipeCount = 0;
+ m_nTotalParameterCount = 0;
m_nWordThreadAddr = 0;
m_hWorkStop = nullptr;
m_hWorkThreadHandle = nullptr;
m_nTimeoutCount = 0;
+ m_onSyncingStateChanged = nullptr;
::InitializeCriticalSection(&m_cs);
}
@@ -61,6 +63,9 @@
m_nTimeoutCount = 0;
unlock();
+ if (m_onSyncingStateChanged != nullptr) {
+ m_onSyncingStateChanged(m_nSyncStatus);
+ }
if (m_hWorkStop == nullptr) {
m_hWorkStop = ::CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -77,9 +82,25 @@
m_nSyncStatus = SS_FAILED;
m_nTimeoutCount = 0;
unlock();
+
+ if (m_onSyncingStateChanged != nullptr) {
+ m_onSyncingStateChanged(m_nSyncStatus);
+ }
}
- int CRecipesManager::decodeRecipeListReport(const char* pszData, size_t size)
+ void CRecipesManager::syncTimeout()
+ {
+ lock();
+ m_nSyncStatus = SS_TIMEOUT;
+ m_nTimeoutCount = 0;
+ unlock();
+
+ if (m_onSyncingStateChanged != nullptr) {
+ m_onSyncingStateChanged(m_nSyncStatus);
+ }
+ }
+
+ short CRecipesManager::decodeRecipeListReport(const char* pszData, size_t size)
{
int index = 0;
int unitNo, reportType, totalMasterRecipeCount;
@@ -124,26 +145,132 @@
ASSERT(pRecipeList);
- // 这里暂时只处理reportType=4,即Request from EAS
- if (reportType == 4) {
- int nRet = pRecipeList->addRecipePacket(toatlGroupCount, currentGroupCount, pszIdsData, 250 * 2);
+ /*
+ 1: Create
+ 2: Modify
+ 3: Delete
+ 4: Request from EAS
+ */
+ if (reportType == RT_CREATE) {
+
+ }
+ else if (reportType == RT_MODIFY) {
+
+ }
+ else if (reportType == RT_DELETE) {
+
+ }
+ else if (reportType == RT_REQUEST_FROM_EAS) {
+ int nRet = pRecipeList->addRecipePacket(totalMasterRecipeCount, toatlGroupCount, currentGroupCount, pszIdsData, 250 * 2);
if (MRLRC_CURRENT_RECIPE_COMPLETE == nRet) {
lock();
- if (m_nTotalMasterRecipeCount == m_mapRecipesTemp.size()) {
- for (auto item : m_mapRecipes) {
- delete item.second;
- }
- m_mapRecipes = m_mapRecipesTemp;
- m_mapRecipesTemp.clear();
- m_nSyncStatus = SS_COMPLETE;
- unlock();
- return MRLRC_OK;
+ for (auto item : m_mapRecipes) {
+ delete item.second;
}
+ m_mapRecipes = m_mapRecipesTemp;
+ m_mapRecipesTemp.clear();
+ m_nSyncStatus = SS_LIST_COMPLETE;
unlock();
+
+ if (m_onSyncingStateChanged != nullptr) {
+ m_onSyncingStateChanged(m_nSyncStatus);
+ }
+
+ return MRLRC_OK;
}
else if (MRLRC_CONTINUE == nRet) {
return MRLRC_CONTINUE;
}
+ }
+
+
+ return MRLRC_OK;
+ }
+
+ short CRecipesManager::decodeRecipeParameterReport(const char* pszData, size_t size)
+ {
+ int index = 0;
+ int masterRecipeId, localRecipeId, unitNo, reportType;
+ int totalParameterCount;
+ int toatlGroupCount, currentGroupCount;
+ const char* pszParameterData;
+
+ masterRecipeId = CToolUnits::toInt16(&pszData[index]);
+ index += 2;
+
+ localRecipeId = CToolUnits::toInt16(&pszData[index]);
+ index += 2;
+
+ unitNo = CToolUnits::toInt16(&pszData[index]);
+ index += 2;
+
+ reportType = CToolUnits::toInt16(&pszData[index]);
+ index += 2;
+
+ totalParameterCount = CToolUnits::toInt16(&pszData[index]);
+ index += 2;
+
+ toatlGroupCount = CToolUnits::toInt16(&pszData[index]);
+ index += 2;
+
+ currentGroupCount = CToolUnits::toInt16(&pszData[index]);
+ index += 2;
+
+ pszParameterData = &pszData[index];
+
+
+ lock();
+ if (m_nTotalParameterCount == 0) m_nTotalParameterCount = toatlGroupCount;
+ if (m_nTotalParameterCount != toatlGroupCount) {
+ return MRLRC_MASTER_RECIPE_LIST_COUNT_NG;
+ }
+ m_nTimeoutCount = 0;
+ unlock();
+
+
+
+
+ // 找到对应CRecipeList, 找不到则返回NG
+ lock();
+ CRecipeList* pRecipeList = getRecipeList(unitNo);
+ if (pRecipeList == nullptr) {
+ unlock();
+ return MRLRC_NG;
+ }
+ unlock();
+
+ /*
+ 1: Create
+ 2: Modify
+ 3: Delete
+ 4: Request from EAS
+ */
+ if (reportType == RT_CREATE) {
+
+ }
+ else if (reportType == RT_MODIFY) {
+
+ }
+ else if (reportType == RT_DELETE) {
+
+ }
+ else if (reportType == RT_REQUEST_FROM_EAS) {
+ int nRet = pRecipeList->addParamsPacket(totalParameterCount, toatlGroupCount, currentGroupCount,
+ unitNo, localRecipeId,
+ pszParameterData, 250 * 2);
+ if (MRLRC_CURRENT_RECIPE_COMPLETE == nRet) {
+ lock();
+ m_nSyncStatus = SS_PARAMS_COMPLETE;
+ unlock();
+
+ if (m_onSyncingStateChanged != nullptr) {
+ m_onSyncingStateChanged(m_nSyncStatus);
+ }
+
+ return MRLRC_OK;
+ }
+
+ return nRet;
}
@@ -155,6 +282,35 @@
auto iter = m_mapRecipesTemp.find(unitNo);
if (iter == m_mapRecipesTemp.end()) return nullptr;
return iter->second;
+ }
+
+ CRecipeList* CRecipesManager::getRecipeList(int unitNo)
+ {
+ auto iter = m_mapRecipes.find(unitNo);
+ if (iter == m_mapRecipes.end()) return nullptr;
+ return iter->second;
+ }
+
+ bool CRecipesManager::saveRecipeList(int unitNo, std::string& strFilepath)
+ {
+ CRecipeList* pRecipeList = getRecipeList(unitNo);
+ if (pRecipeList == nullptr) return false;
+ return pRecipeList->serialize(strFilepath);
+ }
+
+ bool CRecipesManager::readRecipeList(int unitNo, std::string& strFilepath)
+ {
+ CRecipeList* pRecipeList = getRecipeList(unitNo);
+ if (pRecipeList == nullptr) {
+ pRecipeList = new CRecipeList();
+ m_mapRecipes[unitNo] = pRecipeList;
+ }
+ return pRecipeList->deserialize(strFilepath);
+ }
+
+ void CRecipesManager::setOnSyncingStateChanged(ONSYNCINGSTATECHANGED block)
+ {
+ m_onSyncingStateChanged = block;
}
unsigned CRecipesManager::TimeoutCheckWorkingProc()
@@ -170,9 +326,10 @@
if (m_nSyncStatus == SS_SYNCING) {
m_nTimeoutCount++;
if (m_nTimeoutCount > 10) {
- m_nSyncStatus = SS_TIMEOUT;
unlock();
+ syncTimeout();
TRACE("CRecipesManager::TimeoutCheckWorkingProc 超时退出\n");
+ lock();
}
}
--
Gitblit v1.9.3