!4649 fix dfile clean code problem

Merge pull request !4649 from YanMing/231206_catchBug
This commit is contained in:
openharmony_ci 2024-01-10 04:51:42 +00:00 committed by Gitee
commit e87793a200
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
22 changed files with 44 additions and 72 deletions

View File

@ -20,10 +20,6 @@
#include "nstackx_util.h"
#include "securec.h"
#define TAG "nStackXCongestion"
#define WIFI_BITRATE_ACCURACY 1000
#define WIFI_SIGNAL_MINIMUM (-100)
#define WIFI_QDISC_LENGTH 1000
#define WIFI_STA_INFO_FAKE_RX_RATE 216

View File

@ -43,6 +43,8 @@ static int32_t ProcessQdiscInfoInner(struct rtattr *tb[], int32_t parent)
len = NlMin((int32_t)RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), (int32_t)sizeof(q));
if (memcpy_s(&q, len, RTA_DATA(tbs[TCA_STATS_QUEUE]), len) == NSTACKX_EOK) {
return q.qlen;
} else {
LOGE(TAG, "memcpy_s failed");
}
}

View File

@ -15,26 +15,12 @@
#include "nstackx_wifi_stat_hook.h"
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <securec.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/timerfd.h>
#include <linux/socket.h>
#include "nstackx_congestion.h"
#include "nstackx_error.h"
#include "nstackx_log.h"
#include "nstackx_timer.h"
#include "nstackx_util.h"
#include "nstackx_dev.h"
#define TAG "nStackXCongestion"
static GetWifiInfoHook g_getWifiInfoHook = NULL;

View File

@ -248,8 +248,6 @@ int32_t GetStationHandler(struct nl_msg *msg, HandleParam *handleParam)
{
NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, handleParam->mac);
return 0;
nla_put_failure:
return -ENOBUFS;
}
int32_t GetWifiStaInfo(const NLDevInfo nlDevInfo, WifiStationInfo *wifiStationInfo)

View File

@ -61,6 +61,11 @@ typedef struct {
OnDFileRenameFile onRenameFile;
} DFileSetRenameHookCtx;
typedef struct {
DFileSession *session;
FileListInfo *fileListInfo;
} DFileSendFileCtx;
static int32_t GetDFileSessionId(uint16_t *sessionId)
{
if (PthreadMutexLock(&g_dFileSessionIdMutex) != 0) {
@ -290,7 +295,6 @@ static uint8_t HasRepeatedNumber(const uint16_t *data, uint16_t len)
return NSTACKX_FALSE;
}
typedef struct {
DFileSession *session;
char *pathList[NSTACKX_MAX_STORAGE_PATH_NUM];
@ -429,11 +433,6 @@ int32_t NSTACKX_DFileSetStoragePathList(int32_t sessionId, const char *path[], c
return NSTACKX_EOK;
}
typedef struct {
DFileSession *session;
FileListInfo *fileListInfo;
} DFileSendFileCtx;
static inline void AddFileList(DFileSession *session, FileListInfo *fileListInfo)
{
#ifdef NSTACKX_SMALL_FILE_SUPPORT

View File

@ -250,7 +250,7 @@ void WaitFileHeaderTimeoutEvent(DFileTransErrorCode errorCode)
void DFileServerCreateEvent(void)
{
char valueStr[DFile_EVENT_NAME_LEN];
char valueStr[DFile_EVENT_NAME_LEN] = "";
char eventName[DFile_EVENT_NAME_LEN] = "Server created";
DFileEventParam temp;

View File

@ -12,21 +12,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "nstackx_dfile_log.h"
#include <stdint.h>
#include <securec.h>
#include "nstackx_error.h"
#define TAG "nStackXDFile"
static uint32_t g_dfileLogLevel = DFILE_LOG_LEVEL_INFO;
uint32_t GetDFileLogLevel(void)
{
return g_dfileLogLevel;
}
void SetDFileLogLevel(uint32_t logLevel)
{
if (logLevel >= DFILE_LOG_LEVEL_END) {

View File

@ -13,13 +13,13 @@
* limitations under the License.
*/
#include "nstackx_dfile_send.h"
#include "nstackx_dfile_mp.h"
#include "nstackx_dfile_log.h"
#include "nstackx_dfile_send.h"
#include "nstackx_dfile_transfer.h"
#include "nstackx_file_manager.h"
#include "nstackx_dfile_log.h"
#include "nstackx_dfile_dfx.h"
#include "securec.h"
#define TAG "nStackXDfileMp"
int32_t DFileSocketRecvSP(DFileSession *session)
@ -101,6 +101,7 @@ int32_t CreateSenderThread(DFileSession *session)
para = malloc(sizeof(SenderThreadPara));
if (para == NULL) {
DFILE_LOGE(TAG, "Failed to allocate memory for SenderThreadPara");
return NSTACKX_ENOMEM;
}
para->session = session;

View File

@ -49,8 +49,8 @@ static void SendBackPressureFrame(DFileTrans *dFileTrans)
allSize = recvListAllSize + recvInnerAllSize;
uint32_t recvListWindowSize = (dFileTrans->fileManager->iowMaxRate * DFILE_KILOBYTES / NSTACKX_MILLI_TICKS)
* NSTACKX_ACK_INTERVAL * FILE_RECV_LIST_SLOW_START_RATE;
if (((allSize >= dFileTrans->fileManager->iowCount * FILE_RECV_LIST_IO_WRITE_THRESHOLD) ||
(allSize >= dFileTrans->fileManager->maxRecvBlockListSize * FILE_RECV_LIST_IO_WRITE_THRESHOLD) ||
if (((allSize >= (uint32_t)(dFileTrans->fileManager->iowCount * FILE_RECV_LIST_IO_WRITE_THRESHOLD)) ||
(allSize >= (uint32_t)(dFileTrans->fileManager->maxRecvBlockListSize * FILE_RECV_LIST_IO_WRITE_THRESHOLD)) ||
(allSize * blockFrameSize >= recvListWindowSize)) &&
allSize > 0) {
dFileTrans->fileManager->recvListOverIo = 1;

View File

@ -24,6 +24,7 @@
#define MAX_NR_IOVCNT 20
#define MAX_UDP_PAYLOAD 65507
#define MAX_SEND_COUNT 1
static inline uint32_t GetIovListSize(void)
{
@ -189,7 +190,7 @@ static int32_t CheckUnsentList(List *unsent, List *head, int32_t maxCount)
static int32_t GetMaxSendCount(void)
{
return 1;
return MAX_SEND_COUNT;
}
static int32_t DoSendDataFrame(DFileSession *session, List *head, int32_t count, uint32_t tid, uint8_t socketIndex)

View File

@ -75,14 +75,12 @@ static QueueNode *CreateQueueNode(const uint8_t *frame, size_t length,
queueNode->sendLen = 0;
if (memcpy_s(queueNode->frame, length, frame, length) != EOK) {
free(queueNode->frame);
free(queueNode);
DestroyQueueNode(queueNode);
return NULL;
}
if (peerAddr != NULL) {
if (memcpy_s(&queueNode->peerAddr, sizeof(struct sockaddr_in), peerAddr, sizeof(struct sockaddr_in)) != EOK) {
free(queueNode->frame);
free(queueNode);
DestroyQueueNode(queueNode);
return NULL;
}
}
@ -486,7 +484,7 @@ void DFileSessionSendSetting(PeerInfo *peerInfo)
return;
}
}
int32_t ret = DFileWriteHandle(buf, frameLen, peerInfo);
if (ret != (int32_t)frameLen && ret != NSTACKX_EAGAIN) {
data.errorCode = NSTACKX_EFAILED;
@ -918,8 +916,7 @@ int32_t DFileWriteHandle(const uint8_t *frame, size_t len, void *context)
if (PthreadMutexLock(&session->outboundQueueLock) != 0) {
DFILE_LOGE(TAG, "pthread mutex lock failed");
free(queueNode->frame);
free(queueNode);
DestroyQueueNode(queueNode);
return NSTACKX_EFAILED;
}
ListInsertTail(&session->outboundQueue, &queueNode->list);
@ -1827,7 +1824,7 @@ void *DFileReceiverHandle(void *arg)
break;
}
}
DFILE_LOGI(TAG, "Total recv blocks: direct %llu inner %llu", session->recvBlockNumDirect,
DFILE_LOGI(TAG, "Total recv blocks: direct %llu inner %llu", session->recvBlockNumDirect,
session->recvBlockNumInner);
if (ret < 0 && ret != NSTACKX_EAGAIN && ret != NSTACKX_PEER_CLOSE) {
PostFatalEvent(session);

View File

@ -20,7 +20,6 @@
#include "nstackx_dfile.h"
#include "nstackx_dfile_frame.h"
#include "nstackx_dfile_session.h"
#include "nstackx_dfile_mp.h"
#include "nstackx_error.h"
#include "nstackx_file_manager.h"
#include "nstackx_list.h"
@ -73,7 +72,8 @@ static const char *GetSendStateMessage(DFileSendState state)
[STATE_SEND_FILE_FAIL] = "send file fail",
};
for (uint32_t i = 0; i < sizeof(message) / sizeof(message[0]); i++) {
uint32_t msgLen = sizeof(message) / sizeof(message[0]);
for (uint32_t i = 0; i < msgLen; i++) {
if (state == i) {
return message[i];
}
@ -95,7 +95,8 @@ static const char *GetReceiveStateMessage(DFileReceiveState state)
[STATE_RECEIVE_FILE_FAIL] = "receive file fail",
};
for (uint32_t i = 0; i < sizeof(message) / sizeof(message[0]); i++) {
uint32_t msgLen = sizeof(message) / sizeof(message[0]);
for (uint32_t i = 0; i < msgLen; i++) {
if (state == i) {
return message[i];
}
@ -424,7 +425,6 @@ static void FileManagerTransMsgHandler(uint16_t fileId, FileManagerMsgType msgTy
static int32_t StartFileManagerSenderTask(DFileTrans *dFileTrans)
{
FileListMsgPara msgPara;
uint32_t i;
FileList *fileList = dFileTrans->fileList;
uint16_t fileNum = FileListGetNum(fileList);
SendFileListInfo sendFileListInfo;
@ -439,6 +439,7 @@ static int32_t StartFileManagerSenderTask(DFileTrans *dFileTrans)
DFILE_LOGE(TAG, "too many files: %u", fileNum);
return NSTACKX_ENOMEM;
}
uint32_t i;
for (i = 0; i < FileListGetNum(fileList); i++) {
sendFileListInfo.fileList[i] = fileList->list[i].fullFileName;
sendFileListInfo.fileSize[i] = fileList->list[i].fileSize;
@ -563,7 +564,6 @@ static void WaitForFileTransferDoneFrame(DFileTrans *dFileTrans, DFileSendState
/* Need to re-send data block. */
if (!FileManagerIsLastBlockRead(dFileTrans->fileManager, dFileTrans->transId)) {
*nextState = STATE_SEND_FILE_DATA_ONGOING;
return;
}
}
@ -635,7 +635,7 @@ static void SetSendState(DFileTrans *dFileTrans, DFileSendState nextState)
if ((nextState == STATE_SEND_FILE_DONE || nextState == STATE_SEND_FILE_FAIL) &&
dFileTrans->fileManagerTaskStarted) {
DFILE_LOGI(TAG, "transId: %u, Send state: %s -> %s", dFileTrans->transId,
DFILE_LOGI(TAG, "transId: %u, Send state: %s -> %s", dFileTrans->transId,
GetSendStateMessage(dFileTrans->sendState),GetSendStateMessage(nextState));
if (FileManagerStopTask(dFileTrans->fileManager, dFileTrans->transId, FILE_LIST_TRANSFER_FINISH) !=
NSTACKX_EOK) {
@ -696,7 +696,6 @@ static void ReceiveFileHeaderOngoing(DFileTrans *dFileTrans, DFileReceiveState *
uint8_t timeout = (GetElapseTime(&dFileTrans->ts) >= dFileTrans->timeout) ? NSTACKX_TRUE : NSTACKX_FALSE;
if (dFileTrans->allFileNameReceived || timeout) {
*nextState = STATE_SEND_FILE_HEADER_CONFIRM;
return;
}
}
@ -1015,7 +1014,6 @@ static void WaitForFileTransferDoneAck(DFileTrans *dFileTrans, DFileReceiveState
*nextState = STATE_SEND_FILE_TRANSFER_DONE;
DFILE_LOGI(TAG, "transId %u enter WaitForFileTransferDoneAck and next state is STATE_SEND_FILE_TRANSFER_DONE",
dFileTrans->transId);
return;
}
}

View File

@ -26,7 +26,6 @@
#include "nstackx_openssl.h"
#endif
#include "nstackx_util.h"
#include "nstackx_dev.h"
#include "securec.h"
#define TAG "nStackXDFile"
@ -88,7 +87,6 @@ void NotifyFileManagerMsg(const FileManager *fileManager, FileManagerMsgType msg
void NotifyFileListMsg(const FileListTask *fileList, FileManagerMsgType msgType)
{
FileListMsgCtx *ctx = NULL;
uint64_t bytesTransferred;
if (fileList == NULL) {
DFILE_LOGE(TAG, "NotifyFileListMsg fileList error");
return;
@ -106,8 +104,7 @@ void NotifyFileListMsg(const FileListTask *fileList, FileManagerMsgType msgType)
free(ctx);
return;
}
bytesTransferred = fileList->bytesTransferredLastRecord;
ctx->msg.transferUpdate.bytesTransferred = bytesTransferred;
ctx->msg.transferUpdate.bytesTransferred = fileList->bytesTransferredLastRecord;
ctx->msg.transferUpdate.totalBytes = fileList->totalBytes;
ctx->msg.transferUpdate.transId = fileList->transId;
}
@ -265,6 +262,7 @@ static FileListTask *PrepareOneTaskByStatus(FileManager *fileManager, uint32_t r
} else if (runStatus == FILE_LIST_STATUS_STOP) {
ListRemoveNode(&fileList->list);
fileManager->taskList.size--;
} else {
}
isFound = NSTACKX_TRUE;
break;
@ -429,9 +427,6 @@ char *GetFullFilePath(const char *path, const char *fileName)
fullPathLength = (uint32_t)(strlen(path) + sizeof(PATH_SEPARATOR) + strlen(fileName) + sizeof('\0'));
}
if (fullPathLength == 0) {
return NULL;
}
fullPath = (char *)calloc(fullPathLength, sizeof(char));
if (fullPath == NULL) {
DFILE_LOGE(TAG, "full path calloc error");
@ -630,7 +625,7 @@ static int32_t WriteSingleBlockFrame(FileManager *fileManager, FileListTask *fil
payLoad = blockFrame->fileDataFrame->blockPayload;
uint32_t dataLen;
if (fileList->cryptPara.keylen > 0 && payloadLength > 0) {
if (fileList->cryptPara.keylen > 0) {
buffer = (uint8_t *)calloc(payloadLength, 1);
if (buffer == NULL) {
fileList->errCode = FILE_MANAGER_ENOMEM;

View File

@ -202,10 +202,12 @@ int32_t GetEncryptedDataTarFrame(CryptPara *cryptPara, uint16_t fileId, FileList
fileDataFrame->fileId = htons(fileId);
fileDataFrame->blockSequence = htonl(targetSequence);
if (AesGcmEncrypt(buffer->blockPayload, targetLenth, cryptPara, fileDataFrame->blockPayload, payLoadLen) == 0) {
DFILE_LOGE(TAG, "AesGcmEncrypt failed, %d-%d", targetLenth, payLoadLen);
errCode = FILE_MANAGER_FILE_EOTHER;
}
if (memcpy_s(buffer, fileList->maxFrameLength, fileDataFrame, frameOffset + payLoadLen) != EOK) {
DFILE_LOGE(TAG, "memcpy error");
errCode = FILE_MANAGER_FILE_EOTHER;
}
free(fileDataFrame);

View File

@ -28,4 +28,4 @@ void DFileReceiverControlHandle(DFileSession *session);
}
#endif
#endif
#endif //NSTACKX_DFILE_CONTROL_H

View File

@ -383,7 +383,7 @@ typedef void (*DFileEventFunc)(void *softObj, const DFileEvent *info);
NSTACKX_EXPORT void NSTACKX_DFileSetEventFunc(void *softObj, DFileEventFunc func);
typedef void (*DFileLogCallback)(const char *moduleName, uint32_t logLevel, const char *format, ...);
/*
* Set the DFile log implementation
*/

View File

@ -68,7 +68,7 @@ int32_t WaitSocketEvent(const DFileSession *session, SocketDesc fd, uint32_t tim
return NSTACKX_EFAILED;
}
if (ret) {
if (ret != 0) {
if (FD_ISSET(fd, &readFds) && (canRead != NULL)) {
*canRead = NSTACKX_TRUE;
}

View File

@ -14,7 +14,6 @@
*/
#include "nstackx_dev.h"
#include "nstackx_util.h"
#include "nstackx_error.h"
#include "nstackx_log.h"
#include "securec.h"

View File

@ -16,7 +16,6 @@
#include "nstackx_getopt.h"
#include "nstackx_error.h"
#include "nstackx_log.h"
#include "nstackx_util.h"
#define TAG "nStackXGetOpt"
#define NSTACK_GETOPT_MAX_ARGC 100

View File

@ -15,9 +15,7 @@
#include "nstackx_log.h"
#include <errno.h>
#include "securec.h"
#include "nstackx_util.h"
#include "nstackx_error.h"
#define TAG "nStackXLog"
static uint32_t g_logLevel = NSTACKX_LOG_LEVEL_INFO;
@ -28,7 +26,7 @@ static void DefaultLogImpl(const char *tag, uint32_t level, const char *format,
SYSTEMTIME st = {0};
GetLocalTime(&st);
printf("%02d-%02d %02d:%02d:%02d.%03d %d %d %d %s: ", st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
printf("%02u-%02u %02u:%02u:%02u.%03u %d %d %d %s: ", st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,
st.wMilliseconds, GetCurrentProcessId(), GetCurrentThreadId(), level, tag);
vprintf(format, args);
}

View File

@ -247,6 +247,7 @@ uint8_t IsCryptoIncluded(void)
{
return NSTACKX_TRUE;
}
uint8_t QueryCipherSupportByName(char *name)
{
int ret = mbedtls_version_check_feature(name);
@ -257,4 +258,4 @@ uint8_t QueryCipherSupportByName(char *name)
LOGI(TAG, "devices no support %s", name);
return NSTACKX_FALSE;
}
#endif
#endif // MBEDTLS_INCLUDED

View File

@ -99,6 +99,7 @@ uint32_t AesGcmEncryptVec(AesVec *vec, uint32_t vecNum, CryptPara *cryptPara, ui
uint32_t retLen = 0;
if (vecNum == 0 || outLen <= GCM_ADDED_LEN || cryptPara == NULL ||
vec == NULL || outBuf == NULL) {
LOGE(TAG, "Invaid para");
return 0;
}
if (InitEncryptCtx(cryptPara) != NSTACKX_EOK) {
@ -189,6 +190,7 @@ uint32_t AesGcmDecrypt(uint8_t *inBuf, uint32_t inLen, CryptPara *cryptPara, uin
uint8_t buffer[AES_BLOCK_SIZE];
if (inLen <= GCM_ADDED_LEN || outLen < inLen - GCM_ADDED_LEN || cryptPara == NULL ||
inBuf == NULL || outBuf == NULL) {
LOGE(TAG, "Invaid para");
return 0;
}
cryptPara->ivLen = GCM_IV_LENGTH;