diff --git a/.gitignore b/.gitignore index bb9a70e9b284194c308ff5a6d57bd3edfdce6799..77c52b2ee2d00da281cc6ddec32d4003c9b90c2b 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ CMakeError.log /out/isenseconfig/WSL-Clang-Debug /out/isenseconfig/WSL-GCC-Debug /test/cfg -/src/.vs +/src/.vs +*.o diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 9baf49ff211667e8fd83b5494824aa8ba793aba0..1a1305825bb32cd3a300e990a33cca52ec7633b9 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -301,7 +301,9 @@ void tscSaveSubscriptionProgress(void* sub) { char path[256]; sprintf(path, "%s/subscribe", tsDataDir); if (access(path, 0) != 0) { - mkdir(path, 0777); + if (mkdir(path, 0777) != 0 && errno != EEXIST) { + tscError("failed to create subscribe dir: %s", path); + } } sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic); diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 75249e44eefd86f1e8ff1cc30e230ed01c5fcac4..d3c8eefbb9c37d85f1cf72a361f5ff72c9bb93d9 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -80,9 +80,8 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn) { } void taos_init_imp() { - char temp[128]; - struct stat dirstat; - + char temp[128]; + errno = TSDB_CODE_SUCCESS; srand(taosGetTimestampSec()); deltaToUtcInitOnce(); @@ -94,7 +93,9 @@ void taos_init_imp() { taosReadGlobalLogCfg(); // For log directory - if (stat(tsLogDir, &dirstat) < 0) mkdir(tsLogDir, 0755); + if (mkdir(tsLogDir, 0755) != 0 && errno != EEXIST) { + printf("failed to create log dir:%s\n", tsLogDir); + } sprintf(temp, "%s/taoslog", tsLogDir); if (taosInitLog(temp, tsNumOfLogLines, 10) < 0) { diff --git a/src/kit/shell/src/shellImport.c b/src/kit/shell/src/shellImport.c index 1dea6bca702e761850b5fefbba308791655aa00a..347f99671db1bc9147c98d97ec708a3bf8bcf689 100644 --- a/src/kit/shell/src/shellImport.c +++ b/src/kit/shell/src/shellImport.c @@ -148,7 +148,11 @@ static void shellSourceFile(TAOS *con, char *fptr) { } char *fname = full_path.we_wordv[0]; - + if (fname == NULL) { + fprintf(stderr, "ERROR: invalid filename\n"); + return; + } + if (access(fname, F_OK) != 0) { fprintf(stderr, "ERROR: file %s is not exist\n", fptr); @@ -169,6 +173,7 @@ static void shellSourceFile(TAOS *con, char *fptr) { if (f == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); wordfree(&full_path); + free(cmd); return; } diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 81426b683a67cab0a8576236b270800837cb9e5d..ca0af9614524109787e7ac30f9a91d366ac2b164 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -43,6 +43,7 @@ extern char configDir[]; #define MAX_DATA_SIZE 1024 #define MAX_NUM_DATATYPE 8 #define OPT_ABORT 1 /* –abort */ +#define STRING_LEN 512 /* The options we understand. */ static struct argp_option options[] = { @@ -380,10 +381,11 @@ int main(int argc, char *argv[]) { bool insert_only = arguments.insert_only; char **data_type = arguments.datatype; int count_data_type = 0; - char dataString[512]; + char dataString[STRING_LEN]; bool do_aggreFunc = true; - memset(dataString, 0, 512); + memset(dataString, 0, STRING_LEN); + int len = 0; if (strcasecmp(data_type[0], "BINARY") == 0 || strcasecmp(data_type[0], "BOOL") == 0) { do_aggreFunc = false; @@ -392,8 +394,8 @@ int main(int argc, char *argv[]) { if (strcasecmp(data_type[count_data_type], "") == 0) { break; } - strcat(dataString, data_type[count_data_type]); - strcat(dataString, " "); + + len += snprintf(dataString + len, STRING_LEN - len, "%s ", data_type[count_data_type]); } FILE *fp = fopen(arguments.output_file, "a"); @@ -473,32 +475,29 @@ int main(int argc, char *argv[]) { sprintf(command, "create database %s;", db_name); taos_query(taos, command); - char cols[512] = "\0"; + char cols[STRING_LEN] = "\0"; int colIndex = 0; + len = 0; for (; colIndex < ncols_per_record - 1; colIndex++) { if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { - sprintf(command, ",f%d %s", colIndex + 1, data_type[colIndex % count_data_type]); - strcat(cols, command); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s", colIndex + 1, data_type[colIndex % count_data_type]); } else { - sprintf(command, ",f%d %s(%d)", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); - strcat(cols, command); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d)", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); } } if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { - sprintf(command, ",f%d %s)", colIndex + 1, data_type[colIndex % count_data_type]); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s)", colIndex + 1, data_type[colIndex % count_data_type]); } else { - sprintf(command, ",f%d %s(%d))", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); + len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d))", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); } - strcat(cols, command); - if (!use_metric) { /* Create all the tables; */ printf("Creating %d table(s)......\n", ntables); for (int i = 0; i < ntables; i++) { - sprintf(command, "create table %s.%s%d (ts timestamp%s;", db_name, tb_prefix, i, cols); + snprintf(command, BUFFER_SIZE, "create table %s.%s%d (ts timestamp%s;", db_name, tb_prefix, i, cols); queryDB(taos, command); } @@ -508,7 +507,7 @@ int main(int argc, char *argv[]) { } else { /* Create metric table */ printf("Creating meters super table...\n"); - sprintf(command, "create table %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols); + snprintf(command, BUFFER_SIZE, "create table %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols); queryDB(taos, command); printf("meters created!\n"); @@ -522,10 +521,10 @@ int main(int argc, char *argv[]) { j = i % 10; } if (j % 2 == 0) { - sprintf(command, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j,"shanghai"); - } else { - sprintf(command, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j,"beijing"); - } + snprintf(command, BUFFER_SIZE, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "shanghai"); + } else { + snprintf(command, BUFFER_SIZE, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "beijing"); + } queryDB(taos, command); } diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 7875ef732ce5e3b526675a26f1c2b7c1940ea445..f03b46ac470e828bdb62b76d31cea796c83fed81 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -117,8 +117,8 @@ typedef struct { } SDbInfo; typedef struct { - char name[TSDB_TABLE_NAME_LEN + 1]; - char metric[TSDB_TABLE_NAME_LEN + 1]; + char name[TSDB_TABLE_NAME_LEN]; + char metric[TSDB_TABLE_NAME_LEN]; } STableRecord; typedef struct { @@ -871,7 +871,7 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) { int fd = -1; STableRecord tableRecord; - strcpy(tableRecord.metric, metric); + tstrncpy(tableRecord.metric, metric, TSDB_TABLE_NAME_LEN); sprintf(command, "select tbname from %s", metric); result = taos_query(taos, command); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 9634d2c645d8be6a7cab1147b4a551b099209d53..7ea5188b96a47981f5c42e9c28389f8cd0410409 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -27,7 +27,7 @@ void * tsAcctSdb = NULL; static int32_t tsAcctUpdateSize; -static void mnodeCreateRootAcct(); +static int32_t mnodeCreateRootAcct(); static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) { SAcctObj *pAcct = pOper->pObj; @@ -79,7 +79,11 @@ static int32_t mnodeAcctActionDecode(SSdbOper *pOper) { static int32_t mnodeAcctActionRestored() { if (dnodeIsFirstDeploy()) { - mnodeCreateRootAcct(); + int32_t code = mnodeCreateRootAcct(); + if (code != TSDB_CODE_SUCCESS) { + mError("failed to create root account, reason:%s", tstrerror(code)); + return code; + } } acctInit(); @@ -161,9 +165,9 @@ void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) { mnodeDecAcctRef(pAcct); } -static void mnodeCreateRootAcct() { +static int32_t mnodeCreateRootAcct() { int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb); - if (numOfAccts != 0) return; + if (numOfAccts != 0) return TSDB_CODE_SUCCESS; SAcctObj *pAcct = malloc(sizeof(SAcctObj)); memset(pAcct, 0, sizeof(SAcctObj)); @@ -190,7 +194,8 @@ static void mnodeCreateRootAcct() { .table = tsAcctSdb, .pObj = pAcct, }; - sdbInsertRow(&oper); + + return sdbInsertRow(&oper); } #ifndef _ACCT diff --git a/src/mnode/src/mnodeMain.c b/src/mnode/src/mnodeMain.c index 298d10993beee3262a5dbebc6184a8f5a40d8b73..57bb1b2bac5c0293aabec3e81c74d8661a89fd00 100644 --- a/src/mnode/src/mnodeMain.c +++ b/src/mnode/src/mnodeMain.c @@ -88,9 +88,9 @@ int32_t mnodeStartSystem() { } mPrint("starting to initialize mnode ..."); - struct stat dirstat; - if (stat(tsMnodeDir, &dirstat) < 0) { - mkdir(tsMnodeDir, 0755); + if (mkdir(tsMnodeDir, 0755) != 0 && errno != EEXIST) { + mError("failed to init mnode dir:%s, reason:%s", tsMnodeDir, strerror(errno)); + return -1; } dnodeAllocateMnodeWqueue(); diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index 36e7d13a867b6c2ccae1044758eb1c63e4c66356..30f491ec032bbac8b54dade8b883f15e618520ab 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -316,7 +316,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { } sprintf(pConnectRsp->acctId, "%x", pAcct->acctId); - strcpy(pConnectRsp->serverVersion, version); + memcpy(pConnectRsp->serverVersion, version, TSDB_VERSION_LEN); pConnectRsp->writeAuth = pUser->writeAuth; pConnectRsp->superAuth = pUser->superAuth; diff --git a/src/os/linux/src/linuxSysPara.c b/src/os/linux/src/linuxSysPara.c index af2d3c2633fef495c0876b7e4be7f90d336d51fe..ca244dcd949cbc2c9819b0b6e36cfb682268e34c 100644 --- a/src/os/linux/src/linuxSysPara.c +++ b/src/os/linux/src/linuxSysPara.c @@ -229,7 +229,7 @@ static void taosGetSystemLocale() { // get and set default locale uError("can't get locale from system, set it to en_US.UTF-8"); strcpy(tsLocale, "en_US.UTF-8"); } else { - strncpy(tsLocale, locale, tListLen(tsLocale)); + tstrncpy(tsLocale, locale, tListLen(tsLocale)); uError("locale not configured, set to system default:%s", tsLocale); } } diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index 77fc3992723fb719b165fd5d9b22674d006b4a6e..b91b89e21cf5d322b4091e24d36dd3d25a7d2cd0 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -32,12 +32,12 @@ bool httpCheckUsedbSql(char *sql) { void httpTimeToString(time_t t, char *buf, int buflen) { memset(buf, 0, (size_t)buflen); - char ts[30] = {0}; + char ts[32] = {0}; struct tm *ptm; time_t tt = t / 1000; ptm = localtime(&tt); - strftime(ts, 64, "%Y-%m-%d %H:%M:%S", ptm); + strftime(ts, 31, "%Y-%m-%d %H:%M:%S", ptm); sprintf(buf, "%s.%03ld", ts, t % 1000); } diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index 61f9da63688f6d0f541a1fbae56b4d2037978269..ffb2ccb2f932a715da56364069235cd0b98ea0d3 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -313,7 +313,7 @@ bool tgGetPassFromUrl(HttpContext *pContext) { return false; } - strcpy(pContext->pass, pParser->path[TG_PASS_URL_POS].pos); + tstrncpy(pContext->pass, pParser->path[TG_PASS_URL_POS].pos, TSDB_PASSWORD_LEN); return true; } diff --git a/src/util/src/tdes.c b/src/util/src/tdes.c index 00474e4ae29a5e6f910a250d48a3c23b95c3826c..3112fb411148925bf064b356df6e8dfc708ce86e 100644 --- a/src/util/src/tdes.c +++ b/src/util/src/tdes.c @@ -18,6 +18,7 @@ void generate_key(unsigned char* key); void generate_sub_keys(unsigned char* main_key, key_set* key_sets); void process_message(unsigned char* message_piece, unsigned char* processed_piece, key_set* key_sets, int mode); +#if 0 int64_t taosDesGenKey() { unsigned int iseed = (unsigned int)time(NULL); srand(iseed); @@ -27,6 +28,7 @@ int64_t taosDesGenKey() { return *((int64_t*)key); } +#endif char* taosDesImp(unsigned char* key, char* src, unsigned int len, int process_mode) { unsigned int number_of_blocks = len / 8; diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 91d586322d47b97c02e981aa3e324391d431fa0a..31ed6e2f7bded579b75066e590c68b8bc8580a3e 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -87,6 +87,10 @@ void *taosThreadToOpenNewNote(void *param) umask(0); int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + if (fd < 0) { + return NULL; + } + taosLockNote(fd, pNote); lseek(fd, 0, SEEK_SET); diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 256ef3c72baf0ccc5dd0c39b1f6452a9dfd204d6..9ec982b1decf00be2043d4c68004943c41c93587 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -75,19 +75,29 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { return TSDB_CODE_SUCCESS; } - mkdir(tsVnodeDir, 0755); + if (mkdir(tsVnodeDir, 0755) != 0 && errno != EEXIST) { + vError("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), tsVnodeDir); + if (errno == EACCES) { + return TSDB_CODE_VND_NO_DISK_PERMISSIONS; + } else if (errno == ENOSPC) { + return TSDB_CODE_VND_NO_DISKSPACE; + } else if (errno == ENOENT) { + return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR; + } else { + return TSDB_CODE_VND_INIT_FAILED; + } + } char rootDir[TSDB_FILENAME_LEN] = {0}; sprintf(rootDir, "%s/vnode%d", tsVnodeDir, pVnodeCfg->cfg.vgId); - if (mkdir(rootDir, 0755) != 0) { - vPrint("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir); + if (mkdir(rootDir, 0755) != 0 && errno != EEXIST) { + vError("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir); if (errno == EACCES) { return TSDB_CODE_VND_NO_DISK_PERMISSIONS; } else if (errno == ENOSPC) { return TSDB_CODE_VND_NO_DISKSPACE; } else if (errno == ENOENT) { return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR; - } else if (errno == EEXIST) { } else { return TSDB_CODE_VND_INIT_FAILED; }