From 251fdf2c9711388e9eccf4b203595b6dc8beee48 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 27 Sep 2020 11:12:38 +0000 Subject: [PATCH] TD-1617 defect found by coverity scan --- src/dnode/src/dnodeModule.c | 4 ++-- src/mnode/src/mnodeTable.c | 4 ++-- src/os/src/detail/osDir.c | 3 ++- src/plugins/http/src/httpParser.c | 25 +++++++++++++++---------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/dnode/src/dnodeModule.c b/src/dnode/src/dnodeModule.c index 0a5b9b550c..18a293d415 100644 --- a/src/dnode/src/dnodeModule.c +++ b/src/dnode/src/dnodeModule.c @@ -147,13 +147,13 @@ void dnodeProcessModuleStatus(uint32_t moduleStatus) { } bool dnodeCheckMnodeStarting() { - if (tsModuleStatus & TSDB_MOD_MNODE) return false; + if (tsModuleStatus & (1 << TSDB_MOD_MNODE)) return false; SDMMnodeInfos *mnodes = dnodeGetMnodeInfos(); for (int32_t i = 0; i < mnodes->nodeNum; ++i) { SDMMnodeInfo *node = &mnodes->nodeInfos[i]; if (node->nodeId == dnodeGetDnodeId()) { - uint32_t moduleStatus = tsModuleStatus | (1 << TSDB_MOD_MNODE);; + uint32_t moduleStatus = tsModuleStatus | (1 << TSDB_MOD_MNODE); dInfo("start mnode module, module status:%d, new status:%d", tsModuleStatus, moduleStatus); dnodeProcessModuleStatus(moduleStatus); return true; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 43b80f65c8..1bc328800e 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -2093,11 +2093,11 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) { pMeta->precision = pDb->cfg.precision; pMeta->tableType = pTable->info.type; tstrncpy(pMeta->tableId, pTable->info.tableId, TSDB_TABLE_FNAME_LEN); - if (pTable->superTable) { + if (pTable->superTable != NULL) { tstrncpy(pMeta->sTableId, pTable->superTable->info.tableId, TSDB_TABLE_FNAME_LEN); } - if (pTable->info.type == TSDB_CHILD_TABLE) { + if (pTable->info.type == TSDB_CHILD_TABLE && pTable->superTable != NULL) { pMeta->sversion = htons(pTable->superTable->sversion); pMeta->tversion = htons(pTable->superTable->tversion); pMeta->numOfTags = (int8_t)pTable->superTable->numOfTags; diff --git a/src/os/src/detail/osDir.c b/src/os/src/detail/osDir.c index 30fd05ffc7..d3f0fda1a5 100644 --- a/src/os/src/detail/osDir.c +++ b/src/os/src/detail/osDir.c @@ -126,12 +126,13 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { dstFp = gzdopen(fd, "wb6f"); if (dstFp == NULL) { ret = -3; + close(fd); goto cmp_end; } while (!feof(srcFp)) { len = (int32_t)fread(data, 1, COMPRESS_STEP_SIZE, srcFp); - gzwrite(dstFp, data, len); + (void)gzwrite(dstFp, data, len); } cmp_end: diff --git a/src/plugins/http/src/httpParser.c b/src/plugins/http/src/httpParser.c index 0c3204687a..b844834537 100644 --- a/src/plugins/http/src/httpParser.c +++ b/src/plugins/http/src/httpParser.c @@ -153,10 +153,10 @@ static int32_t httpOnRequestLine(HttpParser *pParser, char *method, char *target for (int32_t i = 0; i < HTTP_MAX_URL; i++) { char *pSeek = strchr(pStart, '/'); if (pSeek == NULL) { - httpAppendString(pParser->path + i, pStart, strlen(pStart)); + (void)httpAppendString(pParser->path + i, pStart, strlen(pStart)); break; } else { - httpAppendString(pParser->path + i, pStart, (int32_t)(pSeek - pStart)); + (void)httpAppendString(pParser->path + i, pStart, (int32_t)(pSeek - pStart)); } pStart = pSeek + 1; } @@ -485,11 +485,11 @@ void httpClearParser(HttpParser *parser) { } void httpDestroyParser(HttpParser *parser) { + if (!parser) return; + HttpContext *pContext = parser->pContext; httpTrace("context:%p, fd:%d, destroy parser", pContext, pContext->fd); - if (!parser) return; - free(parser->method); parser->method = NULL; free(parser->target); parser->target = NULL; free(parser->version); parser->version = NULL; @@ -684,23 +684,28 @@ static int32_t httpParserOnVersion(HttpParser *parser, HTTP_PARSER_STATE state, break; } - if (c!='0' && c!='1') { + if (c != '0' && c != '1' && c != '2') { httpError("context:%p, fd:%d, parser state:%d, unexpected char:[%c]%02x", pContext, pContext->fd, state, c, c); ok = -1; httpOnError(parser, 400, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); break; } + if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_VERSION_FAILED); break; } - - if (c == '0') parser->httpVersion = HTTP_VERSION_10; - else if (c == '1') parser->httpVersion = HTTP_VERSION_11; - else if (c == '2') parser->httpVersion = HTTP_VERSION_12; - else parser->httpVersion = HTTP_INVALID_VERSION; + + if (c == '0') + parser->httpVersion = HTTP_VERSION_10; + else if (c == '1') + parser->httpVersion = HTTP_VERSION_11; + else if (c == '2') + parser->httpVersion = HTTP_VERSION_12; + else { + } parser->version = strdup(parser->str.str); if (!parser->version) { -- GitLab