From 0f928893e0afbcaade07743a4fa73c0369dc5cb1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 14:27:37 +0000 Subject: [PATCH 1/5] [TD_543] fix coverity scan, cid:267815 --- src/plugins/http/src/tgHandle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index ffb2ccb2f9..ac3df051fd 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -303,7 +303,7 @@ bool tgGetUserFromUrl(HttpContext *pContext) { return false; } - strcpy(pContext->user, pParser->path[TG_USER_URL_POS].pos); + tstrncpy(pContext->user, pParser->path[TG_USER_URL_POS].pos, TSDB_USER_LEN); return true; } From dadb3adecc12178a97b4521680f3108c8507259e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 14:29:43 +0000 Subject: [PATCH 2/5] [TD_543] fix coverity scan, cid:267813 --- src/kit/taosdump/taosdump.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index f03b46ac47..d96f80ed20 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -646,10 +646,9 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp); } - tclose(fd); - remove(".table.tmp"); + close(fd); - return 0; + return remove(".table.tmp"); } void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, SDumpArguments *arguments, FILE *fp) { From a8d35dbc49785d280866d61dfaecc942a594b063 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 14:44:55 +0000 Subject: [PATCH 3/5] [TD_543] fix coverity scan, cid:267820 267853 --- src/kit/shell/src/shellEngine.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 954f2cb8a3..f04607f6fa 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -727,10 +727,6 @@ void read_history() { char f_history[TSDB_FILENAME_LEN]; get_history_path(f_history); - if (access(f_history, R_OK) == -1) { - return; - } - FILE *f = fopen(f_history, "r"); if (f == NULL) { fprintf(stderr, "Opening file %s\n", f_history); @@ -809,14 +805,6 @@ void source_file(TAOS *con, char *fptr) { return; } - if (access(fname, R_OK) != 0) { - fprintf(stderr, "ERROR: file %s is not readable\n", fptr); - - wordfree(&full_path); - free(cmd); - return; - } - FILE *f = fopen(fname, "r"); if (f == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); From 45f66a9498267ac106cf1a478fd9b00b07c09377 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 8 Jun 2020 15:07:48 +0000 Subject: [PATCH 4/5] [TD_543] fix coverity scan, cid:267826 --- src/util/src/tlog.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 47521fc36e..01a0eabbca 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -191,15 +191,14 @@ void taosResetLog() { } static bool taosCheckFileIsOpen(char *logFileName) { - int32_t exist = access(logFileName, F_OK); - if (exist != 0) { - return false; - } - - int32_t fd = open(logFileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(logFileName, O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { - printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); - return true; + if (errno == ENOENT) { + return false; + } else { + printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); + return true; + } } if (taosLockFile(fd)) { From da7fd6459a955b21942f567eb1c8b76d079bea4d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 9 Jun 2020 02:40:31 +0000 Subject: [PATCH 5/5] [TD_543] fix coverity scan, cid:267831 --- src/plugins/http/src/gcHandle.c | 22 +++++++++++++++++++-- src/plugins/http/src/httpSql.c | 2 +- src/plugins/http/src/restHandle.c | 32 ++++++++++++++++++++++++++++--- src/plugins/http/src/tgHandle.c | 13 ++++++++++--- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index fbe6757ccb..4120980123 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -22,9 +22,27 @@ #include "taosdef.h" static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest}; -static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL}; +static HttpEncodeMethod gcHeartBeatMethod = { + .startJsonFp = NULL, + .stopJsonFp = gcSendHeartBeatResp, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = NULL, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod gcQueryMethod = { - NULL, gcStopQueryJson, gcBuildQueryJson, NULL, gcInitQueryJson, gcCleanQueryJson, NULL, NULL}; + .startJsonFp = NULL, + .stopJsonFp = gcStopQueryJson, + .buildQueryJsonFp = gcBuildQueryJson, + .buildAffectRowJsonFp = NULL, + .initJsonFp = gcInitQueryJson, + .cleanJsonFp = gcCleanQueryJson, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void gcInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &gcDecodeMethod); } diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index af9ad8e38a..6ff93b3e8a 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -87,7 +87,7 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { } if (code < 0) { - if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : code)) { + if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, -code)) { singleCmd->code = code; httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql); diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index a2dc7d06a1..d481a654d8 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -22,11 +22,37 @@ static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest}; static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest}; static HttpEncodeMethod restEncodeSqlTimestampMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlTimestampJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlTimestampJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlLocalTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlLocalTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlLocalTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlUtcTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlUtcTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlUtcTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void restInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &restDecodeMethod); diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index ac3df051fd..c6a2230bfb 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -62,9 +62,16 @@ #define TG_MAX_SORT_TAG_SIZE 20 static HttpDecodeMethod tgDecodeMethod = {"telegraf", tgProcessRquest}; -static HttpEncodeMethod tgQueryMethod = {tgStartQueryJson, tgStopQueryJson, NULL, - tgBuildSqlAffectRowsJson, tgInitQueryJson, tgCleanQueryJson, - tgCheckFinished, tgSetNextCmd}; +static HttpEncodeMethod tgQueryMethod = { + .startJsonFp = tgStartQueryJson, + .stopJsonFp = tgStopQueryJson, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = tgBuildSqlAffectRowsJson, + .initJsonFp = tgInitQueryJson, + .cleanJsonFp = tgCleanQueryJson, + .checkFinishedFp = tgCheckFinished, + .setNextCmdFp = tgSetNextCmd +}; static const char DEFAULT_TELEGRAF_CFG[] = "{\"metrics\":["