未验证 提交 ae88f4af 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2190 from taosdata/coverity_scan

Coverity scan
...@@ -64,4 +64,5 @@ CMakeError.log ...@@ -64,4 +64,5 @@ CMakeError.log
/out/isenseconfig/WSL-Clang-Debug /out/isenseconfig/WSL-Clang-Debug
/out/isenseconfig/WSL-GCC-Debug /out/isenseconfig/WSL-GCC-Debug
/test/cfg /test/cfg
/src/.vs /src/.vs
*.o
...@@ -301,7 +301,9 @@ void tscSaveSubscriptionProgress(void* sub) { ...@@ -301,7 +301,9 @@ void tscSaveSubscriptionProgress(void* sub) {
char path[256]; char path[256];
sprintf(path, "%s/subscribe", tsDataDir); sprintf(path, "%s/subscribe", tsDataDir);
if (access(path, 0) != 0) { 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); sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic);
......
...@@ -80,9 +80,8 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn) { ...@@ -80,9 +80,8 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn) {
} }
void taos_init_imp() { void taos_init_imp() {
char temp[128]; char temp[128];
struct stat dirstat;
errno = TSDB_CODE_SUCCESS; errno = TSDB_CODE_SUCCESS;
srand(taosGetTimestampSec()); srand(taosGetTimestampSec());
deltaToUtcInitOnce(); deltaToUtcInitOnce();
...@@ -94,7 +93,9 @@ void taos_init_imp() { ...@@ -94,7 +93,9 @@ void taos_init_imp() {
taosReadGlobalLogCfg(); taosReadGlobalLogCfg();
// For log directory // 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); sprintf(temp, "%s/taoslog", tsLogDir);
if (taosInitLog(temp, tsNumOfLogLines, 10) < 0) { if (taosInitLog(temp, tsNumOfLogLines, 10) < 0) {
......
...@@ -148,7 +148,11 @@ static void shellSourceFile(TAOS *con, char *fptr) { ...@@ -148,7 +148,11 @@ static void shellSourceFile(TAOS *con, char *fptr) {
} }
char *fname = full_path.we_wordv[0]; char *fname = full_path.we_wordv[0];
if (fname == NULL) {
fprintf(stderr, "ERROR: invalid filename\n");
return;
}
if (access(fname, F_OK) != 0) { if (access(fname, F_OK) != 0) {
fprintf(stderr, "ERROR: file %s is not exist\n", fptr); fprintf(stderr, "ERROR: file %s is not exist\n", fptr);
...@@ -169,6 +173,7 @@ static void shellSourceFile(TAOS *con, char *fptr) { ...@@ -169,6 +173,7 @@ static void shellSourceFile(TAOS *con, char *fptr) {
if (f == NULL) { if (f == NULL) {
fprintf(stderr, "ERROR: failed to open file %s\n", fname); fprintf(stderr, "ERROR: failed to open file %s\n", fname);
wordfree(&full_path); wordfree(&full_path);
free(cmd);
return; return;
} }
......
...@@ -43,6 +43,7 @@ extern char configDir[]; ...@@ -43,6 +43,7 @@ extern char configDir[];
#define MAX_DATA_SIZE 1024 #define MAX_DATA_SIZE 1024
#define MAX_NUM_DATATYPE 8 #define MAX_NUM_DATATYPE 8
#define OPT_ABORT 1 /* –abort */ #define OPT_ABORT 1 /* –abort */
#define STRING_LEN 512
/* The options we understand. */ /* The options we understand. */
static struct argp_option options[] = { static struct argp_option options[] = {
...@@ -380,10 +381,11 @@ int main(int argc, char *argv[]) { ...@@ -380,10 +381,11 @@ int main(int argc, char *argv[]) {
bool insert_only = arguments.insert_only; bool insert_only = arguments.insert_only;
char **data_type = arguments.datatype; char **data_type = arguments.datatype;
int count_data_type = 0; int count_data_type = 0;
char dataString[512]; char dataString[STRING_LEN];
bool do_aggreFunc = true; 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) { if (strcasecmp(data_type[0], "BINARY") == 0 || strcasecmp(data_type[0], "BOOL") == 0) {
do_aggreFunc = false; do_aggreFunc = false;
...@@ -392,8 +394,8 @@ int main(int argc, char *argv[]) { ...@@ -392,8 +394,8 @@ int main(int argc, char *argv[]) {
if (strcasecmp(data_type[count_data_type], "") == 0) { if (strcasecmp(data_type[count_data_type], "") == 0) {
break; 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"); FILE *fp = fopen(arguments.output_file, "a");
...@@ -473,32 +475,29 @@ int main(int argc, char *argv[]) { ...@@ -473,32 +475,29 @@ int main(int argc, char *argv[]) {
sprintf(command, "create database %s;", db_name); sprintf(command, "create database %s;", db_name);
taos_query(taos, command); taos_query(taos, command);
char cols[512] = "\0"; char cols[STRING_LEN] = "\0";
int colIndex = 0; int colIndex = 0;
len = 0;
for (; colIndex < ncols_per_record - 1; colIndex++) { for (; colIndex < ncols_per_record - 1; colIndex++) {
if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { 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]);
strcat(cols, command);
} else { } 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 (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { 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 { } 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) { if (!use_metric) {
/* Create all the tables; */ /* Create all the tables; */
printf("Creating %d table(s)......\n", ntables); printf("Creating %d table(s)......\n", ntables);
for (int i = 0; i < ntables; i++) { 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); queryDB(taos, command);
} }
...@@ -508,7 +507,7 @@ int main(int argc, char *argv[]) { ...@@ -508,7 +507,7 @@ int main(int argc, char *argv[]) {
} else { } else {
/* Create metric table */ /* Create metric table */
printf("Creating meters super table...\n"); 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); queryDB(taos, command);
printf("meters created!\n"); printf("meters created!\n");
...@@ -522,10 +521,10 @@ int main(int argc, char *argv[]) { ...@@ -522,10 +521,10 @@ int main(int argc, char *argv[]) {
j = i % 10; j = i % 10;
} }
if (j % 2 == 0) { 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"); 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 { } 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, "beijing");
} }
queryDB(taos, command); queryDB(taos, command);
} }
......
...@@ -117,8 +117,8 @@ typedef struct { ...@@ -117,8 +117,8 @@ typedef struct {
} SDbInfo; } SDbInfo;
typedef struct { typedef struct {
char name[TSDB_TABLE_NAME_LEN + 1]; char name[TSDB_TABLE_NAME_LEN];
char metric[TSDB_TABLE_NAME_LEN + 1]; char metric[TSDB_TABLE_NAME_LEN];
} STableRecord; } STableRecord;
typedef struct { typedef struct {
...@@ -871,7 +871,7 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) { ...@@ -871,7 +871,7 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) {
int fd = -1; int fd = -1;
STableRecord tableRecord; STableRecord tableRecord;
strcpy(tableRecord.metric, metric); tstrncpy(tableRecord.metric, metric, TSDB_TABLE_NAME_LEN);
sprintf(command, "select tbname from %s", metric); sprintf(command, "select tbname from %s", metric);
result = taos_query(taos, command); result = taos_query(taos, command);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
void * tsAcctSdb = NULL; void * tsAcctSdb = NULL;
static int32_t tsAcctUpdateSize; static int32_t tsAcctUpdateSize;
static void mnodeCreateRootAcct(); static int32_t mnodeCreateRootAcct();
static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) { static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) {
SAcctObj *pAcct = pOper->pObj; SAcctObj *pAcct = pOper->pObj;
...@@ -79,7 +79,11 @@ static int32_t mnodeAcctActionDecode(SSdbOper *pOper) { ...@@ -79,7 +79,11 @@ static int32_t mnodeAcctActionDecode(SSdbOper *pOper) {
static int32_t mnodeAcctActionRestored() { static int32_t mnodeAcctActionRestored() {
if (dnodeIsFirstDeploy()) { 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(); acctInit();
...@@ -161,9 +165,9 @@ void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) { ...@@ -161,9 +165,9 @@ void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) {
mnodeDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
static void mnodeCreateRootAcct() { static int32_t mnodeCreateRootAcct() {
int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb); int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb);
if (numOfAccts != 0) return; if (numOfAccts != 0) return TSDB_CODE_SUCCESS;
SAcctObj *pAcct = malloc(sizeof(SAcctObj)); SAcctObj *pAcct = malloc(sizeof(SAcctObj));
memset(pAcct, 0, sizeof(SAcctObj)); memset(pAcct, 0, sizeof(SAcctObj));
...@@ -190,7 +194,8 @@ static void mnodeCreateRootAcct() { ...@@ -190,7 +194,8 @@ static void mnodeCreateRootAcct() {
.table = tsAcctSdb, .table = tsAcctSdb,
.pObj = pAcct, .pObj = pAcct,
}; };
sdbInsertRow(&oper);
return sdbInsertRow(&oper);
} }
#ifndef _ACCT #ifndef _ACCT
......
...@@ -88,9 +88,9 @@ int32_t mnodeStartSystem() { ...@@ -88,9 +88,9 @@ int32_t mnodeStartSystem() {
} }
mPrint("starting to initialize mnode ..."); mPrint("starting to initialize mnode ...");
struct stat dirstat; if (mkdir(tsMnodeDir, 0755) != 0 && errno != EEXIST) {
if (stat(tsMnodeDir, &dirstat) < 0) { mError("failed to init mnode dir:%s, reason:%s", tsMnodeDir, strerror(errno));
mkdir(tsMnodeDir, 0755); return -1;
} }
dnodeAllocateMnodeWqueue(); dnodeAllocateMnodeWqueue();
......
...@@ -316,7 +316,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { ...@@ -316,7 +316,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
} }
sprintf(pConnectRsp->acctId, "%x", pAcct->acctId); sprintf(pConnectRsp->acctId, "%x", pAcct->acctId);
strcpy(pConnectRsp->serverVersion, version); memcpy(pConnectRsp->serverVersion, version, TSDB_VERSION_LEN);
pConnectRsp->writeAuth = pUser->writeAuth; pConnectRsp->writeAuth = pUser->writeAuth;
pConnectRsp->superAuth = pUser->superAuth; pConnectRsp->superAuth = pUser->superAuth;
......
...@@ -229,7 +229,7 @@ static void taosGetSystemLocale() { // get and set default locale ...@@ -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"); uError("can't get locale from system, set it to en_US.UTF-8");
strcpy(tsLocale, "en_US.UTF-8"); strcpy(tsLocale, "en_US.UTF-8");
} else { } else {
strncpy(tsLocale, locale, tListLen(tsLocale)); tstrncpy(tsLocale, locale, tListLen(tsLocale));
uError("locale not configured, set to system default:%s", tsLocale); uError("locale not configured, set to system default:%s", tsLocale);
} }
} }
......
...@@ -32,12 +32,12 @@ bool httpCheckUsedbSql(char *sql) { ...@@ -32,12 +32,12 @@ bool httpCheckUsedbSql(char *sql) {
void httpTimeToString(time_t t, char *buf, int buflen) { void httpTimeToString(time_t t, char *buf, int buflen) {
memset(buf, 0, (size_t)buflen); memset(buf, 0, (size_t)buflen);
char ts[30] = {0}; char ts[32] = {0};
struct tm *ptm; struct tm *ptm;
time_t tt = t / 1000; time_t tt = t / 1000;
ptm = localtime(&tt); 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); sprintf(buf, "%s.%03ld", ts, t % 1000);
} }
......
...@@ -313,7 +313,7 @@ bool tgGetPassFromUrl(HttpContext *pContext) { ...@@ -313,7 +313,7 @@ bool tgGetPassFromUrl(HttpContext *pContext) {
return false; 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; return true;
} }
......
...@@ -18,6 +18,7 @@ void generate_key(unsigned char* key); ...@@ -18,6 +18,7 @@ void generate_key(unsigned char* key);
void generate_sub_keys(unsigned char* main_key, key_set* key_sets); 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); void process_message(unsigned char* message_piece, unsigned char* processed_piece, key_set* key_sets, int mode);
#if 0
int64_t taosDesGenKey() { int64_t taosDesGenKey() {
unsigned int iseed = (unsigned int)time(NULL); unsigned int iseed = (unsigned int)time(NULL);
srand(iseed); srand(iseed);
...@@ -27,6 +28,7 @@ int64_t taosDesGenKey() { ...@@ -27,6 +28,7 @@ int64_t taosDesGenKey() {
return *((int64_t*)key); return *((int64_t*)key);
} }
#endif
char* taosDesImp(unsigned char* key, char* src, unsigned int len, int process_mode) { char* taosDesImp(unsigned char* key, char* src, unsigned int len, int process_mode) {
unsigned int number_of_blocks = len / 8; unsigned int number_of_blocks = len / 8;
......
...@@ -87,6 +87,10 @@ void *taosThreadToOpenNewNote(void *param) ...@@ -87,6 +87,10 @@ void *taosThreadToOpenNewNote(void *param)
umask(0); umask(0);
int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) {
return NULL;
}
taosLockNote(fd, pNote); taosLockNote(fd, pNote);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
......
...@@ -75,19 +75,29 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { ...@@ -75,19 +75,29 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) {
return TSDB_CODE_SUCCESS; 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}; char rootDir[TSDB_FILENAME_LEN] = {0};
sprintf(rootDir, "%s/vnode%d", tsVnodeDir, pVnodeCfg->cfg.vgId); sprintf(rootDir, "%s/vnode%d", tsVnodeDir, pVnodeCfg->cfg.vgId);
if (mkdir(rootDir, 0755) != 0) { if (mkdir(rootDir, 0755) != 0 && errno != EEXIST) {
vPrint("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir); vError("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir);
if (errno == EACCES) { if (errno == EACCES) {
return TSDB_CODE_VND_NO_DISK_PERMISSIONS; return TSDB_CODE_VND_NO_DISK_PERMISSIONS;
} else if (errno == ENOSPC) { } else if (errno == ENOSPC) {
return TSDB_CODE_VND_NO_DISKSPACE; return TSDB_CODE_VND_NO_DISKSPACE;
} else if (errno == ENOENT) { } else if (errno == ENOENT) {
return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR; return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR;
} else if (errno == EEXIST) {
} else { } else {
return TSDB_CODE_VND_INIT_FAILED; return TSDB_CODE_VND_INIT_FAILED;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册