diff --git a/include/os/os.h b/include/os/os.h index e3808065dd..4314148685 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -137,6 +137,14 @@ extern threadlocal bool tsEnableRandErr; terrno = _code; \ } +#define OS_PARAM_CHECK(_o) \ + do { \ + if ((_o) == NULL) { \ + terrno = TSDB_CODE_INVALID_PARA; \ + return terrno; \ + } \ + } while (0) + #ifdef __cplusplus } #endif diff --git a/include/os/osSystem.h b/include/os/osSystem.h index fe181d291a..06f23eec0f 100644 --- a/include/os/osSystem.h +++ b/include/os/osSystem.h @@ -48,8 +48,6 @@ void taosCloseCmd(TdCmdPtr *ppCmd); void *taosLoadDll(const char *filename); -void *taosLoadSym(void *handle, char *name); - void taosCloseDll(void *handle); int32_t taosSetConsoleEcho(bool on); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 5afdf87afb..3c332a6b06 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -56,6 +56,7 @@ static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRe int32_t len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols); if(len < 0) { taosMemoryFree(*pRsp); + *pRsp = NULL; return terrno; } SET_PAYLOAD_LEN((*pRsp)->data, len, len); @@ -957,8 +958,8 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) { _exit: if (terrno != TSDB_CODE_SUCCESS) { - taosMemoryFree(pBlock); taosArrayDestroy(pBlock->pDataBlock); + taosMemoryFree(pBlock); } return terrno; } diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 3ab739334d..24b43ac95b 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -2112,6 +2112,7 @@ static int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) } int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp) { + if(!pCtx || !pRspMsg || !pRsp) return TSDB_CODE_INVALID_PARA; SExplainResNode *node = NULL; int32_t code = 0; bool groupDone = false; @@ -2176,6 +2177,7 @@ _exit: } int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) { + if (!pDag || !pRsp) return TSDB_CODE_INVALID_PARA; int32_t code = 0; SExplainCtx *pCtx = NULL; @@ -2188,6 +2190,7 @@ _return: } int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs) { + if(!pDag || !pCtx) return TSDB_CODE_INVALID_PARA; QRY_ERR_RET(qExplainPrepareCtx(pDag, pCtx)); (*pCtx)->reqStartTs = startTs; @@ -2197,6 +2200,7 @@ int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs) } int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { + if(!pCtx || !pRsp) return TSDB_CODE_INVALID_PARA; int32_t code = 0; pCtx->jobDoneTs = taosGetTimestampUs(); diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 84de563cda..777c6a9216 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -116,7 +116,10 @@ void taosRemoveDir(const char *dirname) { return; } -bool taosDirExist(const char *dirname) { return taosCheckExistFile(dirname); } +bool taosDirExist(const char *dirname) { + if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return false; + return taosCheckExistFile(dirname); +} int32_t taosMkDir(const char *dirname) { if (taosDirExist(dirname)) return 0; @@ -333,6 +336,8 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { } int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { + OS_PARAM_CHECK(dirname); + OS_PARAM_CHECK(outname); wordexp_t full_path; int32_t code = wordexp(dirname, &full_path, 0); switch (code) { @@ -355,6 +360,8 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { } int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) { + OS_PARAM_CHECK(dirname); + OS_PARAM_CHECK(realPath); char tmp[PATH_MAX] = {0}; #ifdef WINDOWS if (_fullpath(tmp, dirname, maxlen) != NULL) { @@ -386,6 +393,10 @@ bool taosIsDir(const char *dirname) { } char *taosDirName(char *name) { + if(name == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } #ifdef WINDOWS char Drive1[MAX_PATH], Dir1[MAX_PATH]; _splitpath(name, Drive1, Dir1, NULL, NULL); @@ -412,12 +423,16 @@ char *taosDirName(char *name) { } char *taosDirEntryBaseName(char *name) { + if(name == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } #ifdef WINDOWS char Filename1[MAX_PATH], Ext1[MAX_PATH]; _splitpath(name, NULL, NULL, Filename1, Ext1); return name + (strlen(name) - strlen(Filename1) - strlen(Ext1)); #else - if (name == NULL || (name[0] == '/' && name[1] == '\0')) return name; + if ((name[0] == '/' && name[1] == '\0')) return name; char *pPoint = strrchr(name, '/'); if (pPoint != NULL) { if (*(pPoint + 1) == '\0') { @@ -515,9 +530,9 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) { } char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) { - /*if (pDirEntry == NULL) {*/ - /*return NULL;*/ - /*}*/ + if (pDirEntry == NULL) { + return NULL; + } #ifdef WINDOWS return pDirEntry->findFileData.cFileName; #else diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index 05c9936c2e..41b34a9030 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -127,8 +127,13 @@ bool osTempSpaceSufficient() { return tsTempSpace.size.avail > tsTempSpace.reser int32_t osSetTimezone(const char *tz) { return taosSetSystemTimezone(tz, tsTimezoneStr, &tsDaylight, &tsTimezone); } void osSetSystemLocale(const char *inLocale, const char *inCharSet) { - (void)memcpy(tsLocale, inLocale, strlen(inLocale) + 1); - (void)memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1); + if (inLocale) (void)memcpy(tsLocale, inLocale, strlen(inLocale) + 1); + if (inCharSet) (void)memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1); } -void osSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; } +void osSetProcPath(int32_t argc, char **argv) { + if (argv == NULL || argc < 1) { + return; // no command line arguments + } + tsProcPath = argv[0]; +} diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 2f18c6e697..c2484860ad 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -80,6 +80,7 @@ typedef struct TdFile { #endif void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) { + if (inputTmpDir == NULL || fileNamePrefix == NULL) return; #ifdef WINDOWS char tmpPath[PATH_MAX]; @@ -120,6 +121,10 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha } int64_t taosCopyFile(const char *from, const char *to) { + if (from == NULL || to == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } #ifdef WINDOWS if (CopyFile(from, to, 0)) { return 1; @@ -133,15 +138,15 @@ int64_t taosCopyFile(const char *from, const char *to) { int64_t bytes; int32_t code = TSDB_CODE_SUCCESS; - // fidfrom = open(from, O_RDONLY); - TdFilePtr pFileFrom = taosOpenFile(from, TD_FILE_READ); + TdFilePtr pFileFrom = NULL; + TdFilePtr pFileTo = NULL; + pFileFrom = taosOpenFile(from, TD_FILE_READ); if (pFileFrom == NULL) { code = terrno; goto _err; } - // fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755); - TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL); + pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL); if (pFileTo == NULL) { code = terrno; goto _err; @@ -193,6 +198,10 @@ _err: } TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions) { + if(path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } TdFilePtr fp = taosOpenFile(path, tdFileOptions); if (!fp) { if (terrno == TAOS_SYSTEM_ERROR(ENOENT)) { @@ -213,6 +222,7 @@ TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions) { } int32_t taosRemoveFile(const char *path) { + OS_PARAM_CHECK(path); int32_t code = remove(path); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -222,6 +232,8 @@ int32_t taosRemoveFile(const char *path) { } int32_t taosRenameFile(const char *oldName, const char *newName) { + OS_PARAM_CHECK(oldName); + OS_PARAM_CHECK(newName); #ifdef WINDOWS bool finished = false; @@ -262,6 +274,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { } int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *atime) { + OS_PARAM_CHECK(path); #ifdef WINDOWS struct _stati64 fileStat; int32_t code = _stati64(path, &fileStat); @@ -335,6 +348,10 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) { } FILE *taosOpenFileForStream(const char *path, int32_t tdFileOptions) { + if (path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } char *mode = NULL; if (tdFileOptions & TD_FILE_APPEND) { mode = (tdFileOptions & TD_FILE_TEXT) ? "at+" : "ab+"; @@ -358,6 +375,10 @@ FILE *taosOpenFileForStream(const char *path, int32_t tdFileOptions) { #ifdef WINDOWS HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { + if (path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return INVALID_HANDLE_VALUE; + } DWORD openMode = 0; DWORD access = 0; DWORD fileFlag = FILE_ATTRIBUTE_NORMAL; @@ -408,6 +429,10 @@ HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { } int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { + if (pFile == NULL || buf == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } #if FILE_WITH_LOCK (void)taosThreadRwlockRdlock(&(pFile->rwlock)); #endif @@ -435,7 +460,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { } int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { - if (pFile == NULL || pFile->hFile == NULL) { + if (pFile == NULL || pFile->hFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; } @@ -457,7 +482,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { } int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) { - if (pFile == NULL) { + if (pFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; } @@ -719,6 +744,10 @@ bool lastErrorIsFileNotExist() { #else int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { + if (path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } int access = O_BINARY; access |= (tdFileOptions & TD_FILE_CREATE) ? O_CREAT : 0; if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) { @@ -742,6 +771,10 @@ int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { } int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { + if (pFile == NULL || buf == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } STUB_RAND_IO_ERR(terrno) #if FILE_WITH_LOCK (void)taosThreadRwlockRdlock(&(pFile->rwlock)); @@ -797,7 +830,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { STUB_RAND_IO_ERR(terrno) - if (pFile == NULL) { + if (pFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; } @@ -843,7 +876,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) { STUB_RAND_IO_ERR(terrno) - if (pFile == NULL) { + if (pFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; } @@ -1050,6 +1083,10 @@ bool lastErrorIsFileNotExist() { return terrno == TAOS_SYSTEM_ERROR(ENOENT); } #endif // WINDOWS TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { + if (path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } STUB_RAND_IO_ERR(NULL) FILE *fp = NULL; #ifdef WINDOWS @@ -1399,6 +1436,10 @@ int32_t taosEOFFile(TdFilePtr pFile) { } bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { + if (pathname == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return false; // invalid parameter + } int flags = 0; if (tdFileAccessOptions & TD_FILE_ACCESS_EXIST_OK) { @@ -1422,6 +1463,8 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); }; int32_t taosCompressFile(char *srcFileName, char *destFileName) { + OS_PARAM_CHECK(srcFileName); + OS_PARAM_CHECK(destFileName); int32_t compressSize = 163840; int32_t ret = 0; int32_t len = 0; @@ -1516,6 +1559,10 @@ int32_t taosLinkFile(char *src, char *dst) { } FILE *taosOpenCFile(const char *filename, const char *mode) { + if (filename == NULL || mode == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } STUB_RAND_IO_ERR(NULL) FILE *f = fopen(filename, mode); if (NULL == f) { @@ -1525,6 +1572,10 @@ FILE *taosOpenCFile(const char *filename, const char *mode) { } int taosSeekCFile(FILE *file, int64_t offset, int whence) { + if(NULL == file) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } #ifdef WINDOWS return _fseeki64(file, offset, whence); #else @@ -1538,6 +1589,10 @@ int taosSeekCFile(FILE *file, int64_t offset, int whence) { } size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream) { + if (buffer == NULL || stream == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } STUB_RAND_IO_ERR(terrno) return fread(buffer, size, count, stream); } diff --git a/source/os/src/osLocale.c b/source/os/src/osLocale.c index becf0d5a70..21f781c7e4 100644 --- a/source/os/src/osLocale.c +++ b/source/os/src/osLocale.c @@ -52,6 +52,9 @@ typedef struct CharsetPair { } CharsetPair; char *taosCharsetReplace(char *charsetstr) { + if (charsetstr == NULL) { + return NULL; + } CharsetPair charsetRep[] = { {"utf8", "UTF-8"}, {"936", "CP936"}, @@ -76,6 +79,8 @@ char *taosCharsetReplace(char *charsetstr) { * In case that the setLocale failed to be executed, the right charset needs to be set. */ int32_t taosSetSystemLocale(const char *inLocale, const char *inCharSet) { + OS_PARAM_CHECK(inLocale); + OS_PARAM_CHECK(inCharSet); if (!taosValidateEncodec(inCharSet)) { return terrno; } @@ -90,6 +95,7 @@ int32_t taosSetSystemLocale(const char *inLocale, const char *inCharSet) { } void taosGetSystemLocale(char *outLocale, char *outCharset) { + if (outLocale == NULL || outCharset == NULL) return; #ifdef WINDOWS char *locale = setlocale(LC_CTYPE, "en_US.UTF-8"); if (locale != NULL) { diff --git a/source/os/src/osSemaphore.c b/source/os/src/osSemaphore.c index e61fd627eb..9327b33f79 100644 --- a/source/os/src/osSemaphore.c +++ b/source/os/src/osSemaphore.c @@ -29,7 +29,11 @@ bool taosCheckPthreadValid(TdThread thread) { return thread.p != NULL; } -void taosResetPthread(TdThread* thread) { thread->p = 0; } +void taosResetPthread(TdThread* thread) { + if (thread != NULL) { + thread->p = NULL; + } +} int64_t taosGetPthreadId(TdThread thread) { #ifdef PTW32_VERSION @@ -46,6 +50,7 @@ bool taosComparePthread(TdThread first, TdThread second) { return first.p == sec int32_t taosGetPId() { return GetCurrentProcessId(); } int32_t taosGetAppName(char* name, int32_t* len) { + OS_PARAM_CHECK(name); char filepath[1024] = {0}; if (GetModuleFileName(NULL, filepath, MAX_PATH) == 0) { @@ -75,6 +80,8 @@ int32_t taosGetAppName(char* name, int32_t* len) { int32_t taosGetPIdByName(const char* name, int32_t* pPId) { return -1;} int32_t tsem_wait(tsem_t* sem) { + OS_PARAM_CHECK(sem); + OS_PARAM_CHECK(*sem); DWORD ret = WaitForSingleObject(*sem, INFINITE); if (ret == WAIT_OBJECT_0) { return 0; @@ -84,6 +91,8 @@ int32_t tsem_wait(tsem_t* sem) { } int32_t tsem_timewait(tsem_t* sem, int64_t timeout_ms) { + OS_PARAM_CHECK(sem); + OS_PARAM_CHECK(*sem); DWORD result = WaitForSingleObject(*sem, timeout_ms); if (result == WAIT_OBJECT_0) { return 0; // Semaphore acquired @@ -96,16 +105,21 @@ int32_t tsem_timewait(tsem_t* sem, int64_t timeout_ms) { // Inter-process sharing is not currently supported. The pshared parameter is invalid. int32_t tsem_init(tsem_t* sem, int pshared, unsigned int value) { + OS_PARAM_CHECK(sem); *sem = CreateSemaphore(NULL, value, LONG_MAX, NULL); return (*sem != NULL) ? 0 : TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } int32_t tsem_post(tsem_t* sem) { + OS_PARAM_CHECK(sem); + OS_PARAM_CHECK(*sem); if (ReleaseSemaphore(*sem, 1, NULL)) return 0; return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } int32_t tsem_destroy(tsem_t* sem) { + OS_PARAM_CHECK(sem); + OS_PARAM_CHECK(*sem); if (CloseHandle(*sem)) return 0; return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } @@ -115,6 +129,7 @@ int32_t tsem_destroy(tsem_t* sem) { #include int32_t tsem_init(tsem_t *psem, int flags, unsigned int count) { + OS_PARAM_CHECK(psem); *psem = dispatch_semaphore_create(count); if (*psem == NULL) return TAOS_SYSTEM_ERROR(errno); return 0; @@ -128,19 +143,19 @@ int32_t tsem_destroy(tsem_t *psem) { } int32_t tsem_post(tsem_t *psem) { - if (psem == NULL || *psem == NULL) return -1; + if (psem == NULL || *psem == NULL) return TSDB_CODE_INVALID_PARA; (void)dispatch_semaphore_signal(*psem); return 0; } int32_t tsem_wait(tsem_t *psem) { - if (psem == NULL || *psem == NULL) return -1; + if (psem == NULL || *psem == NULL) return TSDB_CODE_INVALID_PARA; dispatch_semaphore_wait(*psem, DISPATCH_TIME_FOREVER); return 0; } int32_t tsem_timewait(tsem_t *psem, int64_t milis) { - if (psem == NULL || *psem == NULL) return -1; + if (psem == NULL || *psem == NULL) return TSDB_CODE_INVALID_PARA; dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC)); if (dispatch_semaphore_wait(*psem, time) == 0) { return 0; @@ -158,13 +173,18 @@ int64_t taosGetSelfPthreadId() { int64_t taosGetPthreadId(TdThread thread) { return (int64_t)thread; } -void taosResetPthread(TdThread *thread) { *thread = NULL; } +void taosResetPthread(TdThread *thread) { + if (thread) { + *thread = NULL; + } +} bool taosComparePthread(TdThread first, TdThread second) { return taosThreadEqual(first, second) ? true : false; } int32_t taosGetPId() { return (int32_t)getpid(); } int32_t taosGetAppName(char *name, int32_t *len) { + OS_PARAM_CHECK(name); char buf[PATH_MAX + 1]; buf[0] = '\0'; proc_name(getpid(), buf, sizeof(buf) - 1); @@ -196,7 +216,11 @@ int64_t taosGetSelfPthreadId() { } int64_t taosGetPthreadId(TdThread thread) { return (int64_t)thread; } -void taosResetPthread(TdThread* thread) { *thread = 0; } +void taosResetPthread(TdThread* thread) { + if (thread) { + *thread = 0; + } +} bool taosComparePthread(TdThread first, TdThread second) { return first == second; } int32_t taosGetPId() { @@ -207,6 +231,7 @@ int32_t taosGetPId() { } int32_t taosGetAppName(char* name, int32_t* len) { + OS_PARAM_CHECK(name); const char* self = "/proc/self/exe"; char path[PATH_MAX] = {0}; @@ -233,6 +258,8 @@ int32_t taosGetAppName(char* name, int32_t* len) { } int32_t taosGetPIdByName(const char* name, int32_t* pPId) { + OS_PARAM_CHECK(name); + OS_PARAM_CHECK(pPId); DIR* dir = NULL; struct dirent* ptr = NULL; FILE* fp = NULL; @@ -294,6 +321,7 @@ int32_t tsem_init(tsem_t* psem, int flags, unsigned int count) { } int32_t tsem_timewait(tsem_t* sem, int64_t ms) { + OS_PARAM_CHECK(sem); int ret = 0; struct timespec ts = {0}; @@ -322,6 +350,7 @@ int32_t tsem_timewait(tsem_t* sem, int64_t ms) { } int32_t tsem_wait(tsem_t* sem) { + OS_PARAM_CHECK(sem); int ret = 0; do { ret = sem_wait(sem); @@ -336,6 +365,7 @@ int32_t tsem_wait(tsem_t* sem) { } int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { + OS_PARAM_CHECK(sem); int ret = taosThreadMutexInit(&sem->mutex, NULL); if (ret != 0) return ret; @@ -365,6 +395,7 @@ int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { } int32_t tsem_post(tsem_t* psem) { + OS_PARAM_CHECK(psem); if (sem_post(psem) == 0) { return 0; } else { @@ -373,6 +404,7 @@ int32_t tsem_post(tsem_t* psem) { } int32_t tsem_destroy(tsem_t* sem) { + OS_PARAM_CHECK(sem); if (sem_destroy(sem) == 0) { return 0; } else { @@ -381,6 +413,7 @@ int32_t tsem_destroy(tsem_t* sem) { } int tsem2_post(tsem2_t* sem) { + OS_PARAM_CHECK(sem); int32_t code = taosThreadMutexLock(&sem->mutex); if (code) { return code; @@ -401,6 +434,7 @@ int tsem2_post(tsem2_t* sem) { } int tsem2_destroy(tsem2_t* sem) { + OS_PARAM_CHECK(sem); (void)taosThreadMutexDestroy(&sem->mutex); (void)taosThreadCondDestroy(&sem->cond); (void)taosThreadCondAttrDestroy(&sem->attr); @@ -409,6 +443,7 @@ int tsem2_destroy(tsem2_t* sem) { } int32_t tsem2_wait(tsem2_t* sem) { + OS_PARAM_CHECK(sem); int32_t code = taosThreadMutexLock(&sem->mutex); if (code) { return code; @@ -434,6 +469,7 @@ int32_t tsem2_wait(tsem2_t* sem) { } int32_t tsem2_timewait(tsem2_t* sem, int64_t ms) { + OS_PARAM_CHECK(sem); int32_t code = 0; code = taosThreadMutexLock(&sem->mutex); diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 5f983d5480..32b1023ed7 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -233,6 +233,8 @@ int32_t taosBlockSIGPIPE() { } int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) { + OS_PARAM_CHECK(fqdn); + OS_PARAM_CHECK(ip); #ifdef WINDOWS // Initialize Winsock WSADATA wsaData; @@ -309,6 +311,7 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) { } int32_t taosGetFqdn(char *fqdn) { + OS_PARAM_CHECK(fqdn); #ifdef WINDOWS // Initialize Winsock WSADATA wsaData; @@ -384,6 +387,9 @@ int32_t taosGetFqdn(char *fqdn) { } void tinet_ntoa(char *ipstr, uint32_t ip) { + if (ipstr == NULL) { + return; + } (void)snprintf(ipstr, TD_IP_LEN, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24); } diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 18da778227..0ee4f1c496 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -25,15 +25,19 @@ extern int wcwidth(wchar_t c); extern int wcswidth(const wchar_t *s, size_t n); char *tstrdup(const char *str) { + if (str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } #ifdef WINDOWS return _strdup(str); #else - char* p = strdup(str); - if (str != NULL && NULL == p) { + char *p = strdup(str); + if (NULL == p) { terrno = TSDB_CODE_OUT_OF_MEMORY; } return p; - + #endif } @@ -41,11 +45,19 @@ char *tstrdup(const char *str) { // No errors are expected to occur char *strsep(char **stringp, const char *delim) { + if (stringp == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } char *s; const char *spanp; int32_t c, sc; char *tok; if ((s = *stringp) == NULL) return (NULL); + if (delim == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } for (tok = s;;) { c = *s++; spanp = delim; @@ -81,6 +93,10 @@ char *taosStrndup(const char *s, int size) { /* Copy no more than N characters of SRC to DEST, returning the address of the terminating '\0' in DEST, if any, or else DEST + N. */ char *stpncpy(char *dest, const char *src, int n) { + if (dest == NULL || src == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } size_t size = strnlen(src, n); memcpy(dest, src, size); dest += size; @@ -117,6 +133,8 @@ int32_t taosStr2int64(const char *str, int64_t *val) { } int32_t taosStr2int16(const char *str, int16_t *val) { + OS_PARAM_CHECK(str); + OS_PARAM_CHECK(val); int64_t tmp = 0; int32_t code = taosStr2int64(str, &tmp); if (code) { @@ -130,6 +148,8 @@ int32_t taosStr2int16(const char *str, int16_t *val) { } int32_t taosStr2int32(const char *str, int32_t *val) { + OS_PARAM_CHECK(str); + OS_PARAM_CHECK(val); int64_t tmp = 0; int32_t code = taosStr2int64(str, &tmp); if (code) { @@ -143,6 +163,8 @@ int32_t taosStr2int32(const char *str, int32_t *val) { } int32_t taosStr2int8(const char *str, int8_t *val) { + OS_PARAM_CHECK(str); + OS_PARAM_CHECK(val); int64_t tmp = 0; int32_t code = taosStr2int64(str, &tmp); if (code) { @@ -156,6 +178,9 @@ int32_t taosStr2int8(const char *str, int8_t *val) { } int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) { + if ((f1_ucs4 == NULL || f2_ucs4 == NULL)) { + return TSDB_CODE_INVALID_PARA; + } for (int32_t i = 0; i < bytes; i += sizeof(TdUcs4)) { int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i); int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i); @@ -191,6 +216,9 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) { } int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) { + if (target_ucs4 == NULL || source_ucs4 == NULL || len_ucs4 <= 0) { + return TSDB_CODE_INVALID_PARA; + } if (taosMemorySize(target_ucs4) < len_ucs4 * sizeof(TdUcs4)) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -261,6 +289,10 @@ void taosConvDestroy() { } iconv_t taosAcquireConv(int32_t *idx, ConvType type) { + if(idx == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return (iconv_t)-1; + } if (gConvMaxNum[type] <= 0) { *idx = -1; if (type == M2C) { @@ -321,6 +353,13 @@ void taosReleaseConv(int32_t idx, iconv_t conv, ConvType type) { } bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len) { + if (ucs4_max_len == 0) { + return true; + } + if(ucs4_max_len < 0 || mbs == NULL || ucs4 == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return false; + } #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); terrno = TSDB_CODE_APP_ERROR; @@ -359,6 +398,13 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4 // if success, return the number of bytes written to mbs ( >= 0) // otherwise return error code ( < 0) int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) { + if (ucs4_max_len == 0) { + return 0; + } + if(ucs4_max_len < 0 || ucs4 == NULL || mbs == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); terrno = TSDB_CODE_APP_ERROR; @@ -390,6 +436,13 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) { // if success, return the number of bytes written to mbs ( >= 0) // otherwise return error code ( < 0) int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv) { + if (ucs4_max_len == 0) { + return 0; + } + if(ucs4_max_len < 0 || ucs4 == NULL || mbs == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); terrno = TSDB_CODE_APP_ERROR; @@ -408,6 +461,10 @@ int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t c } bool taosValidateEncodec(const char *encodec) { + if(encodec == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return false; + } #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); terrno = TSDB_CODE_APP_ERROR; @@ -443,7 +500,7 @@ int32_t taosUcs4len(TdUcs4 *ucs4) { // dst buffer size should be at least 2*len + 1 int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len, int32_t bufSize) { - if (!dst) { + if (!dst || !src || bufSize <= 0) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -456,7 +513,7 @@ int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len, int32_t } int32_t taosHexDecode(const char *src, char *dst, int32_t len) { - if (!dst) { + if(!src || !dst || len <= 0) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -475,19 +532,42 @@ int32_t taosHexDecode(const char *src, char *dst, int32_t len) { int32_t taosWcharWidth(TdWchar wchar) { return wcwidth(wchar); } -int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size) { return wcswidth(pWchar, size); } +int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size) { + if (pWchar == NULL || size <= 0) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + return wcswidth(pWchar, size); +} -int32_t taosMbToWchar(TdWchar *pWchar, const char *pStr, int32_t size) { return mbtowc(pWchar, pStr, size); } +int32_t taosMbToWchar(TdWchar *pWchar, const char *pStr, int32_t size) { + if (pWchar == NULL || pStr == NULL || size <= 0) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + return mbtowc(pWchar, pStr, size); +} -int32_t taosMbsToWchars(TdWchar *pWchars, const char *pStrs, int32_t size) { return mbstowcs(pWchars, pStrs, size); } +int32_t taosMbsToWchars(TdWchar *pWchars, const char *pStrs, int32_t size) { + if (pWchars == NULL || pStrs == NULL || size <= 0) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + return mbstowcs(pWchars, pStrs, size); +} -int32_t taosWcharToMb(char *pStr, TdWchar wchar) { return wctomb(pStr, wchar); } +int32_t taosWcharToMb(char *pStr, TdWchar wchar) { + OS_PARAM_CHECK(pStr); + return wctomb(pStr, wchar); } char *taosStrCaseStr(const char *str, const char *pattern) { + if (str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } + if (!pattern || !*pattern) return (char *)str; + size_t i; - - if (!*pattern) return (char *)str; - for (; *str; str++) { if (toupper(*str) == toupper(*pattern)) { for (i = 1;; i++) { @@ -500,6 +580,10 @@ char *taosStrCaseStr(const char *str, const char *pattern) { } int64_t taosStr2Int64(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } int64_t tmp = strtoll(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -508,6 +592,10 @@ int64_t taosStr2Int64(const char *str, char **pEnd, int32_t radix) { } uint64_t taosStr2UInt64(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } uint64_t tmp = strtoull(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -516,6 +604,10 @@ uint64_t taosStr2UInt64(const char *str, char **pEnd, int32_t radix) { } int32_t taosStr2Int32(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } int32_t tmp = strtol(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -524,6 +616,10 @@ int32_t taosStr2Int32(const char *str, char **pEnd, int32_t radix) { } uint32_t taosStr2UInt32(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } uint32_t tmp = strtol(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -532,6 +628,10 @@ uint32_t taosStr2UInt32(const char *str, char **pEnd, int32_t radix) { } int16_t taosStr2Int16(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } int32_t tmp = strtol(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -540,6 +640,10 @@ int16_t taosStr2Int16(const char *str, char **pEnd, int32_t radix) { } uint16_t taosStr2UInt16(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } uint32_t tmp = strtoul(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -548,11 +652,19 @@ uint16_t taosStr2UInt16(const char *str, char **pEnd, int32_t radix) { } int8_t taosStr2Int8(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } int32_t tmp = strtol(str, pEnd, radix); return tmp; } uint8_t taosStr2UInt8(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } uint32_t tmp = strtoul(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -561,11 +673,19 @@ uint8_t taosStr2UInt8(const char *str, char **pEnd, int32_t radix) { } double taosStr2Double(const char *str, char **pEnd) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } double tmp = strtod(str, pEnd); return tmp; } float taosStr2Float(const char *str, char **pEnd) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } float tmp = strtof(str, pEnd); return tmp; } @@ -578,6 +698,10 @@ bool isHex(const char *z, uint32_t n) { } bool isValidateHex(const char *z, uint32_t n) { + if(!z) { + terrno = TSDB_CODE_INVALID_PARA; + return false; + } if ((n & 1) != 0) return false; for (size_t i = HEX_PREFIX_LEN; i < n; i++) { if (isxdigit(z[i]) == 0) { @@ -588,6 +712,9 @@ bool isValidateHex(const char *z, uint32_t n) { } int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size) { + OS_PARAM_CHECK(z); + OS_PARAM_CHECK(data); + OS_PARAM_CHECK(size); n -= HEX_PREFIX_LEN; // remove 0x z += HEX_PREFIX_LEN; *size = n / HEX_PREFIX_LEN; @@ -712,6 +839,10 @@ int32_t taosAscii2Hex(const char *z, uint32_t n, void **data, uint32_t *size) { } int64_t tsnprintf(char *dst, int64_t size, const char *format, ...) { + if (dst == NULL || format == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } if (size <= 0) return 0; if (size == 1) { dst[0] = '\0'; diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index bd1a058291..dc3258bf9c 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -154,6 +154,7 @@ static void taosGetProcIOnfos() { #endif static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { + OS_PARAM_CHECK(cpuInfo); int32_t code = 0; #ifdef WINDOWS FILETIME pre_idleTime = {0}; @@ -206,6 +207,7 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { } static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { + OS_PARAM_CHECK(cpuInfo); int32_t code = 0; #ifdef WINDOWS @@ -287,6 +289,7 @@ void taosGetSystemInfo() { } int32_t taosGetEmail(char *email, int32_t maxLen) { + OS_PARAM_CHECK(email); #ifdef WINDOWS return 0; #elif defined(_TD_DARWIN_64) @@ -330,6 +333,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen) { #ifdef WINDOWS bool getWinVersionReleaseName(char *releaseName, int32_t maxLen) { + if(releaseName == NULL) return false; TCHAR szFileName[MAX_PATH]; DWORD dwHandle; DWORD dwLen; @@ -367,6 +371,7 @@ bool getWinVersionReleaseName(char *releaseName, int32_t maxLen) { #endif int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen) { + OS_PARAM_CHECK(releaseName); #ifdef WINDOWS if (!getWinVersionReleaseName(releaseName, maxLen)) { snprintf(releaseName, maxLen, "Windows"); @@ -437,6 +442,8 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t } int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { + OS_PARAM_CHECK(cpuModel); + OS_PARAM_CHECK(numOfCores); #ifdef WINDOWS char value[100]; DWORD bufferSize = sizeof(value); @@ -541,6 +548,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { // Returns the container's CPU quota if successful, otherwise returns the physical CPU cores static int32_t taosCntrGetCpuCores(float *numOfCores) { + OS_PARAM_CHECK(numOfCores); #ifdef WINDOWS return TSDB_CODE_UNSUPPORT_OS; #elif defined(_TD_DARWIN_64) @@ -600,6 +608,7 @@ _end: } int32_t taosGetCpuCores(float *numOfCores, bool physical) { + OS_PARAM_CHECK(numOfCores); #ifdef WINDOWS SYSTEM_INFO info; GetSystemInfo(&info); @@ -702,6 +711,7 @@ int32_t taosGetCpuInstructions(char* sse42, char* avx, char* avx2, char* fma, ch } int32_t taosGetTotalMemory(int64_t *totalKB) { + OS_PARAM_CHECK(totalKB); #ifdef WINDOWS MEMORYSTATUSEX memsStat; memsStat.dwLength = sizeof(memsStat); @@ -723,6 +733,7 @@ int32_t taosGetTotalMemory(int64_t *totalKB) { } int32_t taosGetProcMemory(int64_t *usedKB) { + OS_PARAM_CHECK(usedKB); #ifdef WINDOWS unsigned bytes_used = 0; @@ -769,6 +780,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) { } int32_t taosGetSysMemory(int64_t *usedKB) { + OS_PARAM_CHECK(usedKB); #ifdef WINDOWS MEMORYSTATUSEX memsStat; memsStat.dwLength = sizeof(memsStat); @@ -794,6 +806,8 @@ int32_t taosGetSysMemory(int64_t *usedKB) { } int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { + OS_PARAM_CHECK(dataDir); + OS_PARAM_CHECK(diskSize); #if defined(WINDOWS) unsigned _int64 i64FreeBytesToCaller; unsigned _int64 i64TotalBytes; @@ -839,21 +853,25 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { } int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { + OS_PARAM_CHECK(rchars); + OS_PARAM_CHECK(wchars); + OS_PARAM_CHECK(read_bytes); + OS_PARAM_CHECK(write_bytes); #ifdef WINDOWS IO_COUNTERS io_counter; if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) { - if (rchars) *rchars = io_counter.ReadTransferCount; - if (wchars) *wchars = io_counter.WriteTransferCount; - if (read_bytes) *read_bytes = 0; - if (write_bytes) *write_bytes = 0; + *rchars = io_counter.ReadTransferCount; + *wchars = io_counter.WriteTransferCount; + *read_bytes = 0; + *write_bytes = 0; return 0; } return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); #elif defined(_TD_DARWIN_64) - if (rchars) *rchars = 0; - if (wchars) *wchars = 0; - if (read_bytes) *read_bytes = 0; - if (write_bytes) *write_bytes = 0; + *rchars = 0; + *wchars = 0; + *read_bytes = 0; + *write_bytes = 0; return 0; #else TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM); @@ -900,6 +918,9 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int } int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { + if (rchars == NULL || wchars == NULL || read_bytes == NULL || write_bytes == NULL) { + return TSDB_CODE_INVALID_PARA; + } static int64_t last_rchars = -1; static int64_t last_wchars = -1; static int64_t last_read_bytes = -1; @@ -932,13 +953,15 @@ int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes return 0; } void taosSetDefaultProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { - *rchars = 0; - *wchars = 0; - *read_bytes = 0; - *write_bytes = 0; + if(rchars) *rchars = 0; + if(wchars) *wchars = 0; + if(read_bytes) *read_bytes = 0; + if(write_bytes) *write_bytes = 0; } int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { + OS_PARAM_CHECK(receive_bytes); + OS_PARAM_CHECK(transmit_bytes); *receive_bytes = 0; *transmit_bytes = 0; @@ -994,6 +1017,8 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { } int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { + OS_PARAM_CHECK(receive_bytes); + OS_PARAM_CHECK(transmit_bytes); static int64_t last_receive_bytes = -1; static int64_t last_transmit_bytes = -1; int64_t cur_receive_bytes = 0; @@ -1017,8 +1042,8 @@ int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { return 0; } void taosSetDefaultCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { - *receive_bytes = 0; - *transmit_bytes = 0; + if (receive_bytes) *receive_bytes = 0; + if (transmit_bytes) *transmit_bytes = 0; } void taosKillSystem() { @@ -1037,6 +1062,7 @@ void taosKillSystem() { #define UUIDLEN (36) int32_t taosGetSystemUUIDLimit36(char *uid, int32_t uidlen) { + OS_PARAM_CHECK(uid); #ifdef WINDOWS GUID guid; HRESULT h = CoCreateGuid(&guid); @@ -1334,6 +1360,7 @@ int32_t getMacLocalHostNameBySCD(char *hostname, size_t maxLen) { #endif int32_t taosGetlocalhostname(char *hostname, size_t maxLen) { + OS_PARAM_CHECK(hostname); #ifdef _TD_DARWIN_64 int res = getMacLocalHostNameBySCD(hostname, maxLen); if (res != 0) { diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index fe52369a53..fefada2142 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -107,26 +107,6 @@ void* taosLoadDll(const char* filename) { #endif } -void* taosLoadSym(void* handle, char* name) { -#if defined(WINDOWS) - return NULL; -#elif defined(_TD_DARWIN_64) - return NULL; -#else - void* sym = dlsym(handle, name); - char* error = NULL; - - if ((error = dlerror()) != NULL) { - // printf("load sym:%s failed, error:%s", name, dlerror()); - return NULL; - } - - // printf("sym %s loaded", name); - - return sym; -#endif -} - void taosCloseDll(void* handle) { #if defined(WINDOWS) return; diff --git a/source/os/src/osThread.c b/source/os/src/osThread.c index 6a8c705cde..f888835d95 100644 --- a/source/os/src/osThread.c +++ b/source/os/src/osThread.c @@ -18,6 +18,8 @@ #include "os.h" int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start)(void *), void *arg) { + OS_PARAM_CHECK(tid); + OS_PARAM_CHECK(start); int32_t code = pthread_create(tid, attr, start, arg); if (code) { taosThreadClear(tid); @@ -28,6 +30,7 @@ int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start) } int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_destroy(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -37,6 +40,8 @@ int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { } int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachstate) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(detachstate); int32_t code = pthread_attr_getdetachstate(attr, detachstate); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -46,6 +51,8 @@ int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachst } int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inheritsched) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(inheritsched); int32_t code = pthread_attr_getinheritsched(attr, inheritsched); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -55,6 +62,8 @@ int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inherit } int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param *param) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(param); int32_t code = pthread_attr_getschedparam(attr, param); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -64,6 +73,8 @@ int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param } int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(policy); int32_t code = pthread_attr_getschedpolicy(attr, policy); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -73,6 +84,8 @@ int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy) } int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscope) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(contentionscope); int32_t code = pthread_attr_getscope(attr, contentionscope); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -82,6 +95,8 @@ int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscop } int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(stacksize); int32_t code = pthread_attr_getstacksize(attr, stacksize); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -90,7 +105,8 @@ int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize) return code; } -int32_t taosThreadAttrInit(TdThreadAttr *attr) { +int32_t taosThreadAttrInit(TdThreadAttr *attr) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_init(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -100,6 +116,7 @@ int32_t taosThreadAttrInit(TdThreadAttr *attr) { } int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setdetachstate(attr, detachstate); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -109,6 +126,7 @@ int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) { } int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setinheritsched(attr, inheritsched); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -118,6 +136,7 @@ int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched) } int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param *param) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setschedparam(attr, param); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -127,6 +146,7 @@ int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param } int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setschedpolicy(attr, policy); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -136,6 +156,7 @@ int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) { } int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setscope(attr, contentionscope); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -145,6 +166,7 @@ int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) { } int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setstacksize(attr, stacksize); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -163,6 +185,7 @@ int32_t taosThreadCancel(TdThread thread) { } int32_t taosThreadCondDestroy(TdThreadCond *cond) { + OS_PARAM_CHECK(cond); #ifdef __USE_WIN_THREAD return 0; #else @@ -176,6 +199,7 @@ int32_t taosThreadCondDestroy(TdThreadCond *cond) { } int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { + OS_PARAM_CHECK(cond); #ifdef __USE_WIN_THREAD InitializeConditionVariable(cond); return 0; @@ -190,6 +214,7 @@ int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { } int32_t taosThreadCondSignal(TdThreadCond *cond) { + OS_PARAM_CHECK(cond); #ifdef __USE_WIN_THREAD WakeConditionVariable(cond); return 0; @@ -204,6 +229,7 @@ int32_t taosThreadCondSignal(TdThreadCond *cond) { } int32_t taosThreadCondBroadcast(TdThreadCond *cond) { + OS_PARAM_CHECK(cond); #ifdef __USE_WIN_THREAD WakeAllConditionVariable(cond); return 0; @@ -218,6 +244,8 @@ int32_t taosThreadCondBroadcast(TdThreadCond *cond) { } int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { + OS_PARAM_CHECK(cond); + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD if (!SleepConditionVariableCS(cond, mutex, INFINITE)) { return EINVAL; @@ -234,8 +262,10 @@ int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { } int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const struct timespec *abstime) { -#ifdef __USE_WIN_THREAD if (!abstime) return 0; + OS_PARAM_CHECK(cond); + OS_PARAM_CHECK(mutex); +#ifdef __USE_WIN_THREAD if (SleepConditionVariableCS(cond, mutex, (DWORD)(abstime->tv_sec * 1e3 + abstime->tv_nsec / 1e6))) return 0; DWORD error = GetLastError(); if (error == ERROR_TIMEOUT) { @@ -258,6 +288,7 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_condattr_destroy(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -268,10 +299,12 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) { } int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) { + OS_PARAM_CHECK(pshared); #ifdef __USE_WIN_THREAD if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE; return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_condattr_getpshared(attr, pshared); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -285,6 +318,7 @@ int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_condattr_init(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -300,6 +334,7 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) { #elif defined(__APPLE__) return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_condattr_setclock(attr, clockId); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -310,6 +345,7 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) { } int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) { + OS_PARAM_CHECK(attr); #ifdef __USE_WIN_THREAD return 0; #else @@ -336,10 +372,12 @@ int32_t taosThreadEqual(TdThread t1, TdThread t2) { } void taosThreadExit(void *valuePtr) { - return pthread_exit(valuePtr); + if(valuePtr) return pthread_exit(valuePtr); } int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) { + OS_PARAM_CHECK(policy); + OS_PARAM_CHECK(param); int32_t code = pthread_getschedparam(thread, policy, param); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -362,6 +400,7 @@ int32_t taosThreadJoin(TdThread thread, void **valuePtr) { } int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) { + OS_PARAM_CHECK(key); int32_t code = pthread_key_create(key, destructor); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -393,6 +432,7 @@ int32_t taosThreadKill(TdThread thread, int32_t sig) { // } int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD DeleteCriticalSection(mutex); return 0; @@ -407,6 +447,7 @@ int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) { } int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD /** * Windows Server 2003 and Windows XP: In low memory situations, InitializeCriticalSection can raise a @@ -426,6 +467,7 @@ int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) } int32_t taosThreadMutexLock(TdThreadMutex *mutex) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD EnterCriticalSection(mutex); return 0; @@ -444,6 +486,7 @@ int32_t taosThreadMutexLock(TdThreadMutex *mutex) { // } int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD if (TryEnterCriticalSection(mutex)) return 0; return EBUSY; @@ -457,6 +500,7 @@ int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) { } int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD LeaveCriticalSection(mutex); return 0; @@ -474,6 +518,7 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_destroy(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -484,10 +529,12 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) { } int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *pshared) { + OS_PARAM_CHECK(pshared); #ifdef __USE_WIN_THREAD if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE; return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_getpshared(attr, pshared); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -502,10 +549,12 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *ps // } int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr *attr, int32_t *kind) { + OS_PARAM_CHECK(kind); #ifdef __USE_WIN_THREAD if (kind) *kind = PTHREAD_MUTEX_NORMAL; return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_gettype(attr, kind); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -519,6 +568,7 @@ int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_init(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -532,6 +582,7 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared) #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_setpshared(attr, pshared); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -549,6 +600,7 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_settype(attr, kind); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -574,6 +626,7 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { */ return 0; #else + OS_PARAM_CHECK(rwlock); int32_t code = pthread_rwlock_destroy(rwlock); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -584,6 +637,7 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { } int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD memset(rwlock, 0, sizeof(*rwlock)); InitializeSRWLock(&rwlock->lock); @@ -599,6 +653,7 @@ int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *a } int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD AcquireSRWLockShared(&rwlock->lock); return 0; @@ -621,6 +676,7 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { // } int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD if (!TryAcquireSRWLockShared(&rwlock->lock)) return EBUSY; return 0; @@ -635,6 +691,7 @@ int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) { } int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD if (!TryAcquireSRWLockExclusive(&rwlock->lock)) return EBUSY; atomic_store_8(&rwlock->excl, 1); @@ -650,6 +707,7 @@ int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) { } int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD if (1 == atomic_val_compare_exchange_8(&rwlock->excl, 1, 0)) { ReleaseSRWLockExclusive(&rwlock->lock); @@ -668,6 +726,7 @@ int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { } int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD AcquireSRWLockExclusive(&rwlock->lock); atomic_store_8(&rwlock->excl, 1); @@ -686,6 +745,7 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_rwlockattr_destroy(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -696,6 +756,7 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) { } int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *pshared) { + OS_PARAM_CHECK(pshared); #ifdef __USE_WIN_THREAD if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE; return 0; @@ -713,6 +774,7 @@ int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_rwlockattr_init(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -726,6 +788,7 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_rwlockattr_setpshared(attr, pshared); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -756,6 +819,7 @@ int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { } int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) { + OS_PARAM_CHECK(param); int32_t code = pthread_setschedparam(thread, policy, param); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -765,6 +829,7 @@ int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sc } int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { + OS_PARAM_CHECK(value); int32_t code = pthread_setspecific(key, value); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -774,6 +839,7 @@ int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { } int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX return pthread_mutex_destroy((pthread_mutex_t *)lock); #else @@ -787,6 +853,7 @@ int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) { } int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX if (pshared != 0) return TSDB_CODE_INVALID_PARA; return pthread_mutex_init((pthread_mutex_t *)lock, NULL); @@ -801,6 +868,7 @@ int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) { } int32_t taosThreadSpinLock(TdThreadSpinlock *lock) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX return pthread_mutex_lock((pthread_mutex_t *)lock); #else @@ -814,6 +882,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock *lock) { } int32_t taosThreadSpinTrylock(TdThreadSpinlock *lock) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX return pthread_mutex_trylock((pthread_mutex_t *)lock); #else @@ -826,6 +895,7 @@ int32_t taosThreadSpinTrylock(TdThreadSpinlock *lock) { } int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX return pthread_mutex_unlock((pthread_mutex_t *)lock); #else @@ -843,6 +913,7 @@ void taosThreadTestCancel(void) { } void taosThreadClear(TdThread *thread) { + if (!thread) return; (void)memset(thread, 0, sizeof(TdThread)); } diff --git a/tests/system-test/2-query/agg_group_NotReturnValue.py b/tests/system-test/2-query/agg_group_NotReturnValue.py index 83f0acd362..059a5c5f2e 100755 --- a/tests/system-test/2-query/agg_group_NotReturnValue.py +++ b/tests/system-test/2-query/agg_group_NotReturnValue.py @@ -1590,11 +1590,9 @@ class TDTestCase(TDTestCase): self.modify_tables() tdSql.execute('alter local "countAlwaysReturnValue" "0"') - for i in range(2): - self.tag_count_all() - self.tbname_count_all() - self.tbname_agg_all() - + self.tag_count_all() + self.tbname_count_all() + self.tbname_agg_all() endTime = time.time() print("total time %ds" % (endTime - startTime))