Revert #242 and improve security when sending files to client

This commit is contained in:
yuanyuanxiang
2025-12-28 14:39:52 +01:00
parent 2d274aab4d
commit 473af822cc
10 changed files with 111 additions and 40 deletions

View File

@@ -593,35 +593,45 @@ BOOL IOCPClient::SendWithSplit(const char* src, ULONG srcSize, ULONG ulSplitLeng
// 依次发送
for (i = ulLength; i >= (int)actualSplitLength; i -= actualSplitLength) {
int j = 0;
for (; j < ulSendRetry; ++j) {
iReturn = SendTo(Travel, actualSplitLength, 0);
if (iReturn > 0) {
int remaining = actualSplitLength;
while (remaining > 0) {
int j = 0;
for (; j < ulSendRetry; ++j) {
iReturn = SendTo(Travel, remaining, 0);
if (iReturn > 0) {
break;
}
}
if (j == ulSendRetry) {
isFail = true;
break;
}
}
if (j == ulSendRetry) {
isFail = true;
break;
}
ulSended += iReturn;
Travel += actualSplitLength;
ulSended += iReturn;
Travel += iReturn;
remaining -= iReturn;
}
if (isFail) break;
}
// 发送最后的部分
if (!isFail && i>0) { //1024
int j = 0;
for (; j < ulSendRetry; j++) {
iReturn = SendTo((char*)Travel,i,0);
if (iReturn > 0) {
int remaining = i;
while (remaining > 0) {
int j = 0;
for (; j < ulSendRetry; j++) {
iReturn = SendTo((char*)Travel, remaining, 0);
if (iReturn > 0) {
break;
}
}
if (j == ulSendRetry) {
isFail = true;
break;
}
ulSended += iReturn;
Travel += iReturn;
remaining -= iReturn;
}
if (j == ulSendRetry) {
isFail = true;
}
ulSended += iReturn;
}
if (szBuffer != src)
SAFE_DELETE_ARRAY(szBuffer);

View File

@@ -418,13 +418,13 @@ void RunFileReceiver(CScreenManager *mgr, const std::string &folder, const std::
if (pClient->ConnectServer(mgr->m_ClientObject->ServerIP().c_str(), mgr->m_ClientObject->ServerPort())) {
pClient->setManagerCallBack(mgr, CManager::DataProcess, CManager::ReconnectProcess);
// 发送目录并准备接收文件
int len = 1 + folder.length() + files.length() + 2;
int len = 1 + folder.length() + files.length() + 1;
char* cmd = new char[len];
cmd[0] = COMMAND_GET_FILE;
memcpy(cmd + 1, folder.c_str(), folder.length());
cmd[1 + folder.length()] = 0;
memcpy(cmd + 1 + folder.length() + 1, files.data(), files.length());
cmd[1 + folder.length() + files.length() + 1] = 0;
cmd[1 + folder.length() + files.length()] = 0;
pClient->Send2Server(cmd, len);
SAFE_DELETE_ARRAY(cmd);
pClient->RunEventLoop(TRUE);