diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c03e3be4eddcc3184e96ec314edf76f66df2a5ea..24e0f48ec9715ec2b1bc1b1e2ba87962ff903728 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -285,8 +285,8 @@ typedef struct STscObj { void * pTimer; char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; - char acctId[TSDB_DB_NAME_LEN]; - char db[TSDB_TABLE_ID_LEN]; + char acctId[TSDB_ACCT_LEN]; + char db[TSDB_DB_NAME_LEN]; char sversion[TSDB_VERSION_LEN]; char writeAuth : 1; char superAuth : 1; diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 91e51f16edbcd597046678a500ea31ef8979380a..52240941f2f80be75afc0832e97acf8d421e5743 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -132,7 +132,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { for (int32_t i = 0; i < numOfRows; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0); char* dst = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i; - STR_WITH_MAXSIZE_TO_VARSTR(dst, pSchema[i].name, TSDB_COL_NAME_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(dst, pSchema[i].name, TSDB_COL_NAME_LEN - 1); char *type = tDataTypeDesc[pSchema[i].type].aName; @@ -171,7 +171,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { // field name TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0); char* output = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i; - STR_WITH_MAXSIZE_TO_VARSTR(output, pSchema[i].name, TSDB_COL_NAME_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(output, pSchema[i].name, TSDB_COL_NAME_LEN - 1); // type name pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1); @@ -211,18 +211,18 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); pQueryInfo->order.order = TSDB_ORDER_ASC; - TAOS_FIELD f = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE}; - strncpy(f.name, "Field", TSDB_COL_NAME_LEN); + TAOS_FIELD f = {.type = TSDB_DATA_TYPE_BINARY, .bytes = (TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE}; + tstrncpy(f.name, "Field", sizeof(f.name)); SFieldSupInfo* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, - TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE, TSDB_COL_NAME_LEN, false); + (TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE, (TSDB_COL_NAME_LEN - 1), false); - rowLen += (TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE); + rowLen += ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE); f.bytes = typeColLength; f.type = TSDB_DATA_TYPE_BINARY; - strncpy(f.name, "Type", TSDB_COL_NAME_LEN); + tstrncpy(f.name, "Type", sizeof(f.name)); pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, typeColLength, @@ -232,7 +232,7 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, f.bytes = sizeof(int32_t); f.type = TSDB_DATA_TYPE_INT; - strncpy(f.name, "Length", TSDB_COL_NAME_LEN); + tstrncpy(f.name, "Length", sizeof(f.name)); pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_INT, sizeof(int32_t), @@ -242,7 +242,7 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, f.bytes = noteColLength; f.type = TSDB_DATA_TYPE_BINARY; - strncpy(f.name, "Note", TSDB_COL_NAME_LEN); + tstrncpy(f.name, "Note", sizeof(f.name)); pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, noteColLength, @@ -286,7 +286,7 @@ static void tscProcessCurrentUser(SSqlObj *pSql) { } static void tscProcessCurrentDB(SSqlObj *pSql) { - char db[TSDB_DB_NAME_LEN + 1] = {0}; + char db[TSDB_DB_NAME_LEN] = {0}; extractDBName(pSql->pTscObj->db, db); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index cbc83c6e75ed5d8c71ec5fe85550a32df19e0651..c4749e461177e037db04f0c85ddede0010c6bdb6 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -795,7 +795,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { STableMetaInfo *pSTableMeterMetaInfo = tscGetMetaInfo(pQueryInfo, STABLE_INDEX); tscSetTableFullName(pSTableMeterMetaInfo, &sToken, pSql); - strncpy(pTag->name, pSTableMeterMetaInfo->name, TSDB_TABLE_ID_LEN); + tstrncpy(pTag->name, pSTableMeterMetaInfo->name, sizeof(pTag->name)); code = tscGetTableMeta(pSql, pSTableMeterMetaInfo); if (code != TSDB_CODE_SUCCESS) { return code; @@ -989,7 +989,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { int validateTableName(char *tblName, int len) { char buf[TSDB_TABLE_ID_LEN] = {0}; - strncpy(buf, tblName, len); + tstrncpy(buf, tblName, sizeof(buf)); SSQLToken token = {.n = len, .type = TK_ID, .z = buf}; tSQLGetToken(buf, &token.type); @@ -1512,7 +1512,7 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) { } pCmd->count = 1; - strncpy(path, pDataBlock->filename, PATH_MAX); + tstrncpy(path, pDataBlock->filename, sizeof(path)); FILE *fp = fopen(path, "r"); if (fp == NULL) { @@ -1520,7 +1520,7 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) { continue; } - strncpy(pTableMetaInfo->name, pDataBlock->tableId, TSDB_TABLE_ID_LEN); + tstrncpy(pTableMetaInfo->name, pDataBlock->tableId, sizeof(pTableMetaInfo->name)); memset(pDataBlock->pData, 0, pDataBlock->nAllocSize); int32_t ret = tscGetTableMeta(pSql, pTableMetaInfo); diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 79d00bf5dc6e9075af64c12de776c8022841e180..55243c43827763c533e9318b767e6c59f1504a1b 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -239,8 +239,7 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { continue; } - strncpy(pQdesc->sql, pSql->sqlstr, TSDB_SHOW_SQL_LEN - 1); - pQdesc->sql[TSDB_SHOW_SQL_LEN - 1] = 0; + tstrncpy(pQdesc->sql, pSql->sqlstr, sizeof(pQdesc->sql)); pQdesc->stime = htobe64(pSql->stime); pQdesc->queryId = htonl(pSql->queryId); pQdesc->useconds = htobe64(pSql->res.useconds); @@ -256,8 +255,7 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { SSqlStream *pStream = pObj->streamList; while (pStream) { - strncpy(pSdesc->sql, pStream->pSql->sqlstr, TSDB_SHOW_SQL_LEN - 1); - pSdesc->sql[TSDB_SHOW_SQL_LEN - 1] = 0; + tstrncpy(pSdesc->sql, pStream->pSql->sqlstr, sizeof(pSdesc->sql)); pSdesc->streamId = htonl(pStream->streamId); pSdesc->num = htobe64(pStream->num); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f29c886cba823e04dba966a0df680df4b126aa32..ab2d7d7830ff02bf3ba9f0b840f5ef842a1c455f 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -348,7 +348,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - if (pToken->n > TSDB_TABLE_NAME_LEN) { + if (pToken->n >= TSDB_TABLE_NAME_LEN) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } @@ -933,7 +933,7 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) { SSchema* pSchema = tscGetTableSchema(pTableMeta); for (int32_t i = 0; i < numOfTags + numOfCols; ++i) { - if (strncasecmp(pTagField->name, pSchema[i].name, TSDB_COL_NAME_LEN) == 0) { + if (strncasecmp(pTagField->name, pSchema[i].name, sizeof(pTagField->name) - 1) == 0) { invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return false; } @@ -993,7 +993,7 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) { // field name must be unique for (int32_t i = 0; i < numOfTags + numOfCols; ++i) { - if (strncasecmp(pColField->name, pSchema[i].name, TSDB_COL_NAME_LEN) == 0) { + if (strncasecmp(pColField->name, pSchema[i].name, sizeof(pColField->name) - 1) == 0) { invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return false; } @@ -1005,7 +1005,8 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) { /* is contained in pFieldList or not */ static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name) { for (int32_t j = startIdx; j < pFieldList->nField; ++j) { - if (strncasecmp(name, pFieldList->p[j].name, TSDB_COL_NAME_LEN) == 0) return true; + TAOS_FIELD* field = pFieldList->p + j; + if (strncasecmp(name, field->name, sizeof(field->name) - 1) == 0) return true; } return false; @@ -1041,7 +1042,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL /* db name is not specified, the tableName dose not include db name */ if (pDB != NULL) { - if (pDB->n > TSDB_DB_NAME_LEN) { + if (pDB->n >= TSDB_DB_NAME_LEN) { return TSDB_CODE_TSC_INVALID_SQL; } @@ -1060,7 +1061,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL } } else { // pDB == NULL, the db prefix name is specified in tableName /* the length limitation includes tablename + dbname + sep */ - if (tableName->n > TSDB_TABLE_NAME_LEN + TSDB_DB_NAME_LEN + tListLen(TS_PATH_DELIMITER)) { + if (tableName->n > (TSDB_TABLE_NAME_LEN - 1) + (TSDB_DB_NAME_LEN - 1) + sizeof(TS_PATH_DELIMITER)) { return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1166,7 +1167,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel /* todo alias name should use the original sql string */ char* name = (pItem->aliasName != NULL)? pItem->aliasName:arithmeticExprStr; - strncpy(pExpr->aliasName, name, TSDB_COL_NAME_LEN); + tstrncpy(pExpr->aliasName, name, sizeof(pExpr->aliasName)); tExprNode* pNode = NULL; SArray* colList = taosArrayInit(10, sizeof(SColIndex)); @@ -1308,7 +1309,7 @@ static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumn SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, pIndex->columnIndex); char* colName = (pItem->aliasName == NULL) ? pSchema->name : pItem->aliasName; - strncpy(pExpr->aliasName, colName, tListLen(pExpr->aliasName)); + tstrncpy(pExpr->aliasName, colName, sizeof(pExpr->aliasName)); SColumnList ids = {0}; ids.num = 1; @@ -1358,7 +1359,7 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum for (int32_t j = 0; j < numOfTotalColumns; ++j) { SSqlExpr* pExpr = doAddProjectCol(pQueryInfo, startPos + j, j, pIndex->tableIndex); - strncpy(pExpr->aliasName, pSchema[j].name, tListLen(pExpr->aliasName)); + tstrncpy(pExpr->aliasName, pSchema[j].name, sizeof(pExpr->aliasName)); pIndex->columnIndex = j; SColumnList ids = {0}; @@ -1401,7 +1402,7 @@ int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pI } if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { - SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE}; + SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE}; strcpy(colSchema.name, TSQL_TBNAME_L); tscAddSpecialColumnForSelect(pQueryInfo, startPos, TSDB_FUNC_TAGPRJ, &index, &colSchema, true); @@ -1448,11 +1449,11 @@ static int32_t setExprInfoForFunctions(SQueryInfo* pQueryInfo, SSchema* pSchema, if (aliasName != NULL) { strcpy(columnName, aliasName); } else { - getRevisedName(columnName, functionID, TSDB_COL_NAME_LEN, pSchema[pColIndex->columnIndex].name); + getRevisedName(columnName, functionID, sizeof(columnName) - 1, pSchema[pColIndex->columnIndex].name); } SSqlExpr* pExpr = tscSqlExprAppend(pQueryInfo, functionID, pColIndex, type, bytes, bytes, false); - strncpy(pExpr->aliasName, columnName, tListLen(pExpr->aliasName)); + tstrncpy(pExpr->aliasName, columnName, sizeof(pExpr->aliasName)); // for all queries, the timestamp column needs to be loaded SColumnIndex index = {.tableIndex = pColIndex->tableIndex, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX}; @@ -1536,7 +1537,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr } memset(pExpr->aliasName, 0, tListLen(pExpr->aliasName)); - getColumnName(pItem, pExpr->aliasName, TSDB_COL_NAME_LEN); + getColumnName(pItem, pExpr->aliasName, sizeof(pExpr->aliasName) - 1); SColumnList ids = getColumnList(1, index.tableIndex, index.columnIndex); if (finalResult) { @@ -1651,7 +1652,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr ids.ids[0] = index; memset(pExpr->aliasName, 0, tListLen(pExpr->aliasName)); - getColumnName(pItem, pExpr->aliasName, TSDB_COL_NAME_LEN); + getColumnName(pItem, pExpr->aliasName, sizeof(pExpr->aliasName) - 1); if (finalResult) { int32_t numOfOutput = tscNumOfFields(pQueryInfo); @@ -1851,7 +1852,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr } memset(pExpr->aliasName, 0, tListLen(pExpr->aliasName)); - getColumnName(pItem, pExpr->aliasName, TSDB_COL_NAME_LEN); + getColumnName(pItem, pExpr->aliasName, sizeof(pExpr->aliasName) - 1); SColumnList ids = getColumnList(1, 0, index.columnIndex); if (finalResult) { @@ -2202,7 +2203,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pDbPrefixToken->type != 0) { assert(pDbPrefixToken->n >= 0); - if (pDbPrefixToken->n > TSDB_DB_NAME_LEN) { // db name is too long + if (pDbPrefixToken->n >= TSDB_DB_NAME_LEN) { // db name is too long return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } @@ -2229,7 +2230,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6); } - if (pCmd->payloadLen > TSDB_TABLE_NAME_LEN) { + if (pCmd->payloadLen >= TSDB_TABLE_NAME_LEN) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } } @@ -3997,7 +3998,7 @@ int32_t tsRewriteFieldNameIfNecessary(SQueryInfo* pQueryInfo) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { char* fieldName = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i)->name; - for (int32_t j = 0; j < TSDB_COL_NAME_LEN && fieldName[j] != 0; ++j) { + for (int32_t j = 0; j < (TSDB_COL_NAME_LEN - 1) && fieldName[j] != 0; ++j) { for (int32_t k = 0; k < tListLen(rep); ++k) { if (fieldName[j] == rep[k]) { fieldName[j] = '_'; @@ -4013,7 +4014,7 @@ int32_t tsRewriteFieldNameIfNecessary(SQueryInfo* pQueryInfo) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { char* fieldName = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i)->name; for (int32_t j = i + 1; j < pQueryInfo->fieldsInfo.numOfOutput; ++j) { - if (strncasecmp(fieldName, tscFieldInfoGetField(&pQueryInfo->fieldsInfo, j)->name, TSDB_COL_NAME_LEN) == 0) { + if (strncasecmp(fieldName, tscFieldInfoGetField(&pQueryInfo->fieldsInfo, j)->name, (TSDB_COL_NAME_LEN - 1)) == 0) { const char* msg = "duplicated column name in new table"; return invalidSqlErrMsg(pQueryInfo->msg, msg); } @@ -4368,7 +4369,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } tVariantListItem* pItem = &pAlterSQL->varList->a[0]; - if (pItem->pVar.nLen > TSDB_COL_NAME_LEN) { + if (pItem->pVar.nLen >= TSDB_COL_NAME_LEN) { return invalidSqlErrMsg(pQueryInfo->msg, msg9); } @@ -4420,7 +4421,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return TSDB_CODE_TSC_INVALID_SQL; } - char name[TSDB_COL_NAME_LEN + 1] = {0}; + char name[TSDB_COL_NAME_LEN] = {0}; strncpy(name, pVarList->a[0].pVar.pz, pVarList->a[0].pVar.nLen); TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); @@ -4522,8 +4523,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return invalidSqlErrMsg(pQueryInfo->msg, msg18); } - char name1[TSDB_COL_NAME_LEN + 1] = {0}; - strncpy(name1, pItem->pVar.pz, pItem->pVar.nLen); + char name1[TSDB_COL_NAME_LEN] = {0}; + tstrncpy(name1, pItem->pVar.pz, sizeof(name1)); TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); } @@ -5232,7 +5233,7 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) { int16_t colIndex = pColIndex->colIndex; if (colIndex == TSDB_TBNAME_COLUMN_INDEX) { type = TSDB_DATA_TYPE_BINARY; - bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; // todo extract method + bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; // todo extract method name = TSQL_TBNAME_L; } else { if (TSDB_COL_IS_TAG(pColIndex->flag)) { @@ -5254,8 +5255,8 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) { SColumnIndex index = {.tableIndex = pQueryInfo->groupbyExpr.tableIndex, .columnIndex = colIndex}; SSqlExpr* pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TAG, &index, type, bytes, bytes, true); - memset(pExpr->aliasName, 0, tListLen(pExpr->aliasName)); - strncpy(pExpr->aliasName, name, TSDB_COL_NAME_LEN); + memset(pExpr->aliasName, 0, sizeof(pExpr->aliasName)); + tstrncpy(pExpr->aliasName, name, sizeof(pExpr->aliasName)); pExpr->colInfo.flag = TSDB_COL_TAG; @@ -6019,7 +6020,7 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* if (pCols != NULL) { // record the involved columns SColIndex colIndex = {0}; - strncpy(colIndex.name, pSchema->name, TSDB_COL_NAME_LEN); + tstrncpy(colIndex.name, pSchema->name, sizeof(colIndex.name)); colIndex.colId = pSchema->colId; colIndex.colIndex = index.columnIndex; diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index 59415f842e8763373aa3d089130eca1d320f80c5..88417addf635fd3cf0824cf6774112c1bfd5a05f 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -115,7 +115,7 @@ bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols) { // 3. valid column names for (int32_t j = i + 1; j < numOfCols; ++j) { - if (strncasecmp(pSchema[i].name, pSchema[j].name, TSDB_COL_NAME_LEN) == 0) { + if (strncasecmp(pSchema[i].name, pSchema[j].name, sizeof(pSchema[i].name) - 1) == 0) { return false; } } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index f96b979105f401d55766271ebd35212ec62ef8c6..8815e463ad9742c0aacd1d38f1de6e5ca56617eb 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -866,7 +866,7 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { assert(pCmd->numOfClause == 1); STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - strncpy(pCreateDbMsg->db, pTableMetaInfo->name, tListLen(pCreateDbMsg->db)); + tstrncpy(pCreateDbMsg->db, pTableMetaInfo->name, sizeof(pCreateDbMsg->db)); return TSDB_CODE_SUCCESS; } @@ -1430,9 +1430,9 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { char *db; // ugly code to move the space db = strstr(pObj->db, TS_PATH_DELIMITER); db = (db == NULL) ? pObj->db : db + 1; - strcpy(pConnect->db, db); - strcpy(pConnect->clientVersion, version); - strcpy(pConnect->msgVersion, ""); + tstrncpy(pConnect->db, db, sizeof(pConnect->db)); + tstrncpy(pConnect->clientVersion, version, sizeof(pConnect->clientVersion)); + tstrncpy(pConnect->msgVersion, "", sizeof(pConnect->msgVersion)); return TSDB_CODE_SUCCESS; } @@ -2153,8 +2153,8 @@ int tscProcessConnectRsp(SSqlObj *pSql) { strcpy(pObj->acctId, pConnect->acctId); // copy acctId from response int32_t len = sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db); - assert(len <= tListLen(pObj->db)); - strncpy(pObj->db, temp, tListLen(pObj->db)); + assert(len <= sizeof(pObj->db)); + tstrncpy(pObj->db, temp, sizeof(pObj->db)); if (pConnect->ipList.numOfIps > 0) tscSetMgmtIpList(&pConnect->ipList); @@ -2338,7 +2338,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf STableMetaInfo *pNewMeterMetaInfo = tscAddEmptyMetaInfo(pNewQueryInfo); assert(pNew->cmd.numOfClause == 1 && pNewQueryInfo->numOfTables == 1); - strncpy(pNewMeterMetaInfo->name, pTableMetaInfo->name, tListLen(pNewMeterMetaInfo->name)); + tstrncpy(pNewMeterMetaInfo->name, pTableMetaInfo->name, sizeof(pNewMeterMetaInfo->name)); memcpy(pNew->cmd.payload, pSql->cmd.payload, pSql->cmd.payloadLen); // tag information if table does not exists. pNew->cmd.payloadLen = pSql->cmd.payloadLen; tscTrace("%p new pSqlObj:%p to get tableMeta, auto create:%d", pSql, pNew, pNew->cmd.autoCreated); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index aab931cf93680df9902c7948c32fbe402a09581e..5f2a8598dbc02b22084d1cded10993fd29c763b7 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -86,21 +86,21 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con pObj->signature = pObj; - strncpy(pObj->user, user, TSDB_USER_LEN); + tstrncpy(pObj->user, user, sizeof(pObj->user)); taosEncryptPass((uint8_t *)pass, strlen(pass), pObj->pass); if (db) { int32_t len = strlen(db); /* db name is too long */ - if (len > TSDB_DB_NAME_LEN) { + if (len >= TSDB_DB_NAME_LEN) { terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH; rpcClose(pDnodeConn); free(pObj); return NULL; } - char tmp[TSDB_DB_NAME_LEN + 1] = {0}; - strcpy(tmp, db); + char tmp[TSDB_DB_NAME_LEN] = {0}; + tstrncpy(tmp, db, sizeof(tmp)); strdequote(tmp); strtolower(pObj->db, tmp); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 84daf63b42cca54dae579783ef6cc2747c69da7c..ddc41e52e52705d2838bef337996f50708bc23c0 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1921,7 +1921,7 @@ static char *getArithemicInputSrc(void *param, const char *name, int32_t colId) for (int32_t i = 0; i < pSupport->numOfCols; ++i) { pExpr = taosArrayGetP(pSupport->exprList, i); - if (strncmp(name, pExpr->aliasName, TSDB_COL_NAME_LEN) == 0) { + if (strncmp(name, pExpr->aliasName, sizeof(pExpr->aliasName) - 1) == 0) { index = i; break; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index fd7d31aa9f198aa14ccec0763d4fedd31e043c09..66fbf9fc9701d4bc33c0dd4a11b17faa53d361bc 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -180,7 +180,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { assert(cfg != NULL); if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - strncpy(configDir, pStr, TSDB_FILENAME_LEN); + tstrncpy(configDir, pStr, TSDB_FILENAME_LEN); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscPrint("set config file directory:%s", pStr); } else { @@ -234,7 +234,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { tscPrint("failed to set locale:%s, current locale:%s", pStr, tsLocale); } - strncpy(tsLocale, locale, tListLen(tsLocale)); + tstrncpy(tsLocale, locale, sizeof(tsLocale)); char *charset = strrchr(tsLocale, sep); if (charset != NULL) { @@ -249,7 +249,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { tscPrint("charset changed from %s to %s", tsCharset, charset); } - strncpy(tsCharset, charset, tListLen(tsCharset)); + tstrncpy(tsCharset, charset, sizeof(tsCharset)); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; } else { @@ -286,7 +286,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { tscPrint("charset changed from %s to %s", tsCharset, pStr); } - strncpy(tsCharset, pStr, tListLen(tsCharset)); + tstrncpy(tsCharset, pStr, sizeof(tsCharset)); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; } else { tscPrint("charset:%s not valid", pStr); @@ -324,7 +324,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { // return -1; // } - strncpy(tsSocketType, pStr, tListLen(tsSocketType)); + tstrncpy(tsSocketType, pStr, sizeof(tsSocketType)); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscPrint("socket type is set:%s", tsSocketType); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index caf424080de9726497e06704191cbe542fcdfc23..a810e5d4be748ef07a7de52fc6b2b018e13eb317 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -801,7 +801,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) { TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes) { TAOS_FIELD f = { .type = type, .bytes = bytes, }; - strncpy(f.name, name, TSDB_COL_NAME_LEN); + tstrncpy(f.name, name, sizeof(f.name)); return f; } @@ -966,12 +966,12 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol if (isTagCol) { SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); pExpr->colInfo.colId = pSchema[pColIndex->columnIndex].colId; - strncpy(pExpr->colInfo.name, pSchema[pColIndex->columnIndex].name, TSDB_COL_NAME_LEN); + tstrncpy(pExpr->colInfo.name, pSchema[pColIndex->columnIndex].name, sizeof(pExpr->colInfo.name)); } else if (pTableMetaInfo->pTableMeta != NULL) { // in handling select database/version/server_status(), the pTableMeta is NULL SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pColIndex->columnIndex); pExpr->colInfo.colId = pSchema->colId; - strncpy(pExpr->colInfo.name, pSchema->name, TSDB_COL_NAME_LEN); + tstrncpy(pExpr->colInfo.name, pSchema->name, sizeof(pExpr->colInfo.name)); } } diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index e010f7fe56ccc7c3f1d4931dd3293a3f1932cf5b..12754b164bc4e50e4f6de8c41a9a072f2ce9b434 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -708,7 +708,7 @@ static void doInitGlobalConfig() { cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; cfg.minValue = 0; cfg.maxValue = 0; - cfg.ptrLength = TSDB_DB_NAME_LEN; + cfg.ptrLength = TSDB_DB_NAME_LEN - 1; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); @@ -923,7 +923,7 @@ static void doInitGlobalConfig() { cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; cfg.minValue = 0; cfg.maxValue = 0; - cfg.ptrLength = TSDB_DB_NAME_LEN; + cfg.ptrLength = TSDB_DB_NAME_LEN - 1; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); diff --git a/src/common/src/tname.c b/src/common/src/tname.c index 3566f26abd944d1f170b2569e8058c08c0478807..d2f5dfc4f75a96e725dc719a4d348472e36d3564 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -28,8 +28,7 @@ void extractTableName(const char* tableId, char* name) { size_t s1 = strcspn(tableId, &TS_PATH_DELIMITER[0]); size_t s2 = strcspn(&tableId[s1 + 1], &TS_PATH_DELIMITER[0]); - strncpy(name, &tableId[s1 + s2 + 2], TSDB_TABLE_NAME_LEN); - name[TSDB_TABLE_NAME_LEN] = 0; + tstrncpy(name, &tableId[s1 + s2 + 2], TSDB_TABLE_NAME_LEN); } char* extractDBName(const char* tableId, char* name) { diff --git a/src/connector/python/linux/python3/taos/cinterface.py b/src/connector/python/linux/python3/taos/cinterface.py index c3c8a4603a3b7dcacea7fa3561cdd455d2e953fa..568e73e355cd774bdf4ffa2e563ae761c25e49ae 100644 --- a/src/connector/python/linux/python3/taos/cinterface.py +++ b/src/connector/python/linux/python3/taos/cinterface.py @@ -130,9 +130,9 @@ _CONVERT_FUNC = { # Corresponding TAOS_FIELD structure in C class TaosField(ctypes.Structure): - _fields_ = [('name', ctypes.c_char * 64), - ('bytes', ctypes.c_short), - ('type', ctypes.c_char)] + _fields_ = [('name', ctypes.c_char * 65), + ('type', ctypes.c_char), + ('bytes', ctypes.c_short)] # C interface class class CTaosInterface(object): diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 73bc2923b25f6d0d4b433a6247cc531a1d98325f..91f146dde4a93000def3fc30982e9c68623da607 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -61,12 +61,10 @@ static const SDnodeComponent tsDnodeComponents[] = { }; static int dnodeCreateDir(const char *dir) { - struct stat dirstat; - if (stat(dir, &dirstat) < 0) { - if (mkdir(dir, 0755) != 0 && errno != EEXIST) { - return -1; - } + if (mkdir(dir, 0755) != 0 && errno != EEXIST) { + return -1; } + return 0; } diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 4b448837fe9c9f0f4dd8a997b54b8011096f9657..e260e7ec81ddee56cfb624f719f3551028c211ed 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -177,10 +177,12 @@ void dnodeDispatchToMgmtQueue(SRpcMsg *pMsg) { memcpy(item, pMsg, sizeof(SRpcMsg)); taosWriteQitem(tsMgmtQueue, 1, item); } else { - SRpcMsg rsp; - rsp.handle = pMsg->handle; - rsp.pCont = NULL; - rsp.code = TSDB_CODE_DND_OUT_OF_MEMORY; + SRpcMsg rsp = { + .handle = pMsg->handle, + .pCont = NULL, + .code = TSDB_CODE_DND_OUT_OF_MEMORY + }; + rpcSendResponse(&rsp); rpcFreeCont(pMsg->pCont); } @@ -188,9 +190,9 @@ void dnodeDispatchToMgmtQueue(SRpcMsg *pMsg) { static void *dnodeProcessMgmtQueue(void *param) { SRpcMsg *pMsg; - SRpcMsg rsp; + SRpcMsg rsp = {0}; int type; - void *handle; + void * handle; while (1) { if (taosReadQitemFromQset(tsMgmtQset, &type, (void **) &pMsg, &handle) == 0) { @@ -251,6 +253,7 @@ static int32_t dnodeOpenVnodes() { if (status != TSDB_CODE_SUCCESS) { dPrint("Get dnode list failed"); + free(vnodeList); return status; } @@ -290,6 +293,7 @@ static void dnodeCloseVnodes() { if (status != TSDB_CODE_SUCCESS) { dPrint("Get dnode list failed"); + free(vnodeList); return; } @@ -456,6 +460,7 @@ static bool dnodeReadMnodeInfos() { return false; } + content[len] = 0; cJSON* root = cJSON_Parse(content); if (root == NULL) { dError("failed to read mnodeIpList.json, invalid json format"); @@ -628,6 +633,7 @@ static bool dnodeReadDnodeCfg() { return false; } + content[len] = 0; cJSON* root = cJSON_Parse(content); if (root == NULL) { dError("failed to read dnodeCfg.json, invalid json format"); diff --git a/src/inc/taos.h b/src/inc/taos.h index 947cbe6759a6dfe580f7972d3f0b8c7eebeef5ff..bf6942be8b7ddff9ffff4af222fb5e938e63d096 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -53,9 +53,9 @@ typedef enum { } TSDB_OPTION; typedef struct taosField { - char name[64]; - short bytes; + char name[65]; uint8_t type; + short bytes; } TAOS_FIELD; #ifdef _TD_GO_DLL_ diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index c75fc70d750b2a8a2f7d70837f536e89eae1180e..1e0ddf0f9f23a10f5e5ad573d78488b2892f896f 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -189,7 +189,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_USERID_LEN 9 #define TS_PATH_DELIMITER_LEN 1 -#define TSDB_METER_ID_LEN_MARGIN 10 +#define TSDB_METER_ID_LEN_MARGIN 8 #define TSDB_TABLE_ID_LEN (TSDB_DB_NAME_LEN+TSDB_TABLE_NAME_LEN+2*TS_PATH_DELIMITER_LEN+TSDB_USERID_LEN+TSDB_METER_ID_LEN_MARGIN) //TSDB_DB_NAME_LEN+TSDB_TABLE_NAME_LEN+2*strlen(TS_PATH_DELIMITER)+strlen(USERID) #define TSDB_UNI_LEN 24 #define TSDB_USER_LEN TSDB_UNI_LEN @@ -200,9 +200,9 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns #define TSDB_NODE_NAME_LEN 64 -#define TSDB_TABLE_NAME_LEN 192 -#define TSDB_DB_NAME_LEN 32 -#define TSDB_COL_NAME_LEN 64 +#define TSDB_TABLE_NAME_LEN 193 +#define TSDB_DB_NAME_LEN 33 +#define TSDB_COL_NAME_LEN 65 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 #define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE #define TSDB_MAX_SQL_SHOW_LEN 256 diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 88c6f9cf26ecf7dbeab27da5f7a514ec5d22b71e..dca8287394f3a6e401c0527daa238875fb88f693 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -224,7 +224,7 @@ typedef struct { typedef struct SSchema { uint8_t type; - char name[TSDB_COL_NAME_LEN + 1]; + char name[TSDB_COL_NAME_LEN]; int16_t colId; int16_t bytes; } SSchema; @@ -250,7 +250,7 @@ typedef struct { typedef struct { char tableId[TSDB_TABLE_ID_LEN + 1]; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; int8_t igExists; int8_t getMeta; int16_t numOfTags; @@ -268,7 +268,7 @@ typedef struct { typedef struct { char tableId[TSDB_TABLE_ID_LEN + 1]; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; int16_t type; /* operation type */ int16_t numOfCols; /* number of schema */ int32_t tagValLen; @@ -502,7 +502,7 @@ typedef struct { typedef struct { char acct[TSDB_USER_LEN + 1]; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; int32_t cacheBlockSize; //MB int32_t totalBlocks; int32_t maxTables; @@ -606,7 +606,7 @@ typedef struct { } SMDVnodeDesc; typedef struct { - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; SMDVnodeCfg cfg; SMDVnodeDesc nodes[TSDB_MAX_REPLICA]; } SMDCreateVnodeMsg; @@ -671,7 +671,7 @@ typedef struct { */ typedef struct { int8_t type; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; uint16_t payloadLen; char payload[]; } SCMShowMsg; diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index d96f80ed206a2f5541daf7bbbd0f4036da4ab7b3..417de629aa5d1724d18fc3fb393d4b0b300a9b57 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -88,21 +88,21 @@ enum _describe_table_index { }; typedef struct { - char field[TSDB_COL_NAME_LEN + 1]; + char field[TSDB_COL_NAME_LEN]; char type[16]; int length; char note[128]; } SColDes; typedef struct { - char name[TSDB_COL_NAME_LEN + 1]; + char name[TSDB_COL_NAME_LEN]; SColDes cols[]; } STableDef; extern char version[]; typedef struct { - char name[TSDB_DB_NAME_LEN + 1]; + char name[TSDB_DB_NAME_LEN]; int32_t replica; int32_t days; int32_t keep; diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index cf9058b9cf02e5a4f475500f9033eb1e645cb83b..35ae9aad33ade1edbc5e37caf952b74cb5413fa5 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -115,7 +115,7 @@ typedef struct { typedef struct SVgObj { uint32_t vgId; - char dbName[TSDB_DB_NAME_LEN + 1]; + char dbName[TSDB_DB_NAME_LEN]; int64_t createdTime; SVnodeGid vnodeGid[TSDB_MAX_REPLICA]; int32_t numOfVnodes; @@ -154,7 +154,7 @@ typedef struct { } SDbCfg; typedef struct SDbObj { - char name[TSDB_DB_NAME_LEN + 1]; + char name[TSDB_DB_NAME_LEN]; char acct[TSDB_USER_LEN + 1]; int64_t createdTime; int32_t cfgVersion; @@ -219,7 +219,7 @@ typedef struct SAcctObj { typedef struct { int8_t type; int32_t index; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; void * pIter; int16_t numOfColumns; int32_t rowSize; diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 90569b4a95a107665e4361a113ada41aaeaa0d88..c80dc3036f786f33b3065c8e7da796a42bfe4059 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -328,8 +328,8 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { if (code != 0) return code; pDb = calloc(1, sizeof(SDbObj)); - strncpy(pDb->name, pCreate->db, TSDB_DB_NAME_LEN); - strncpy(pDb->acct, pAcct->user, TSDB_USER_LEN); + tstrncpy(pDb->name, pCreate->db, sizeof(pDb->name)); + tstrncpy(pDb->acct, pAcct->user, sizeof(pDb->acct)); pDb->createdTime = taosGetTimestampMs(); pDb->cfg = (SDbCfg) { .cacheBlockSize = pCreate->cacheBlockSize, @@ -373,7 +373,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { } bool mnodeCheckIsMonitorDB(char *db, char *monitordb) { - char dbName[TSDB_DB_NAME_LEN + 1] = {0}; + char dbName[TSDB_DB_NAME_LEN] = {0}; extractDBName(db, dbName); size_t len = strlen(dbName); @@ -453,7 +453,7 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - pShow->bytes[cols] = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE; + pShow->bytes[cols] = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); @@ -610,7 +610,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char* name = mnodeGetDbStr(pDb->name); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, TSDB_DB_NAME_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, TSDB_DB_NAME_LEN - 1); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index b9033cdf3c37344222a740198cc1bb2bb06e07e0..8d7482784124264035ed9a2c93afb0f41c93f288 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -43,7 +43,7 @@ typedef enum { } ESdbStatus; typedef struct _SSdbTable { - char tableName[TSDB_DB_NAME_LEN + 1]; + char tableName[TSDB_DB_NAME_LEN]; ESdbTable tableId; ESdbKey keyType; int32_t hashSessions; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 119ba1627dfd188d99518c3345f1037f0641589f..cde94c39b5d230eaa69cb84a57504d9e1e5022ce 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -951,7 +951,7 @@ static int32_t mnodeModifySuperTableTagName(SSuperTableObj *pStable, char *oldTa // update SSchema *schema = (SSchema *) (pStable->schema + pStable->numOfColumns + col); - strncpy(schema->name, newTagName, TSDB_COL_NAME_LEN); + tstrncpy(schema->name, newTagName, sizeof(schema->name)); SSdbOper oper = { .type = SDB_OPER_GLOBAL, @@ -1078,7 +1078,7 @@ static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, int32_t cols = 0; SSchema *pSchema = pMeta->schema; - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); @@ -1138,7 +1138,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, prefixLen = strlen(prefix); SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER; - char stableName[TSDB_TABLE_NAME_LEN + 1] = {0}; + char stableName[TSDB_TABLE_NAME_LEN] = {0}; while (numOfRows < rows) { pShow->pIter = mnodeGetNextSuperTable(pShow->pIter, &pTable); @@ -1151,7 +1151,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, memset(stableName, 0, tListLen(stableName)); mnodeExtractTableName(pTable->info.tableId, stableName); - if (pShow->payloadLen > 0 && patternMatch(pShow->payload, stableName, TSDB_TABLE_NAME_LEN, &info) != TSDB_PATTERN_MATCH) { + if (pShow->payloadLen > 0 && patternMatch(pShow->payload, stableName, sizeof(stableName) - 1, &info) != TSDB_PATTERN_MATCH) { mnodeDecTableRef(pTable); continue; } @@ -1160,7 +1160,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - int16_t len = strnlen(stableName, TSDB_DB_NAME_LEN); + int16_t len = strnlen(stableName, TSDB_DB_NAME_LEN - 1); *(int16_t*) pWrite = len; pWrite += sizeof(int16_t); // todo refactor @@ -1228,7 +1228,7 @@ static int32_t mnodeSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pT assert(numOfCols <= TSDB_MAX_COLUMNS); for (int32_t i = 0; i < numOfCols; ++i) { - strncpy(pSchema->name, pTable->schema[i].name, TSDB_COL_NAME_LEN); + tstrncpy(pSchema->name, pTable->schema[i].name, sizeof(pSchema->name)); pSchema->type = pTable->schema[i].type; pSchema->bytes = htons(pTable->schema[i].bytes); pSchema->colId = htons(pTable->schema[i].colId); @@ -2079,7 +2079,7 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void int32_t cols = 0; SSchema *pSchema = pMeta->schema; - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "table_name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); @@ -2097,7 +2097,7 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "stable_name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); @@ -2141,12 +2141,12 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows continue; } - char tableName[TSDB_TABLE_NAME_LEN + 1] = {0}; + char tableName[TSDB_TABLE_NAME_LEN] = {0}; // pattern compare for table name mnodeExtractTableName(pTable->info.tableId, tableName); - if (pShow->payloadLen > 0 && patternMatch(pShow->payload, tableName, TSDB_TABLE_NAME_LEN, &info) != TSDB_PATTERN_MATCH) { + if (pShow->payloadLen > 0 && patternMatch(pShow->payload, tableName, sizeof(tableName) - 1, &info) != TSDB_PATTERN_MATCH) { mnodeDecTableRef(pTable); continue; } @@ -2155,7 +2155,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows char *pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, TSDB_TABLE_NAME_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, sizeof(tableName) - 1); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -2173,10 +2173,10 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - memset(tableName, 0, tListLen(tableName)); + memset(tableName, 0, sizeof(tableName)); if (pTable->info.type == TSDB_CHILD_TABLE) { mnodeExtractTableName(pTable->superTable->info.tableId, tableName); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, TSDB_TABLE_NAME_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, sizeof(tableName) - 1); } cols++; @@ -2268,7 +2268,7 @@ static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, vo int32_t cols = 0; SSchema *pSchema = pMeta->schema; - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "table_name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); @@ -2331,12 +2331,12 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro continue; } - char tableName[TSDB_TABLE_NAME_LEN + 1] = {0}; + char tableName[TSDB_TABLE_NAME_LEN] = {0}; // pattern compare for table name mnodeExtractTableName(pTable->info.tableId, tableName); - if (pShow->payloadLen > 0 && patternMatch(pShow->payload, tableName, TSDB_TABLE_NAME_LEN, &info) != TSDB_PATTERN_MATCH) { + if (pShow->payloadLen > 0 && patternMatch(pShow->payload, tableName, sizeof(tableName) - 1, &info) != TSDB_PATTERN_MATCH) { mnodeDecTableRef(pTable); continue; } @@ -2345,7 +2345,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro char *pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, TSDB_TABLE_NAME_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, sizeof(tableName) - 1); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/os/darwin/src/darwinPlatform.c b/src/os/darwin/src/darwinPlatform.c index 05290c43f4edb6b413266c73ae149da7a967a1b7..cae65a292729e01da7ced54e40af040b08cc1ac2 100644 --- a/src/os/darwin/src/darwinPlatform.c +++ b/src/os/darwin/src/darwinPlatform.c @@ -189,7 +189,7 @@ void taosGetSystemLocale() { if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { char *locale = setlocale(LC_CTYPE, "chs"); if (locale != NULL) { - strncpy(tsLocale, locale, sizeof(tsLocale) / sizeof(tsLocale[0])); + tstrncpy(tsLocale, locale, sizeof(tsLocale)); cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; uPrint("locale not configured, set to default:%s", tsLocale); } diff --git a/src/os/linux/src/linuxSysPara.c b/src/os/linux/src/linuxSysPara.c index b270eb14cf4c652a531cb0228c949868dc58f7a9..3ec7de3b635253d6936be9137c4c3ee6ff8b4d15 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 { - tstrncpy(tsLocale, locale, tListLen(tsLocale)); + tstrncpy(tsLocale, locale, sizeof(tsLocale)); uError("locale not configured, set to system default:%s", tsLocale); } } @@ -242,7 +242,7 @@ static void taosGetSystemLocale() { // get and set default locale str++; char *revisedCharset = taosCharsetReplace(str); - strncpy(tsCharset, revisedCharset, tListLen(tsCharset)); + tstrncpy(tsCharset, revisedCharset, sizeof(tsCharset)); free(revisedCharset); uWarn("charset not configured, set to system default:%s", tsCharset); diff --git a/src/os/windows/src/twindows.c b/src/os/windows/src/twindows.c index 76b354f7844325f9f35655c640fe43672ec1f94e..82bcc69b11495db45fb1fbc9c943af09c75d0c2e 100644 --- a/src/os/windows/src/twindows.c +++ b/src/os/windows/src/twindows.c @@ -226,7 +226,7 @@ void taosGetSystemLocale() { if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { char *locale = setlocale(LC_CTYPE, "chs"); if (locale != NULL) { - strncpy(tsLocale, locale, sizeof(tsLocale) / sizeof(tsLocale[0])); + tstrncpy(tsLocale, locale, sizeof(tsLocale)); cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; uPrint("locale not configured, set to default:%s", tsLocale); } diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index b91b89e21cf5d322b4091e24d36dd3d25a7d2cd0..1fb63ea2fc4db58e25a78eee51ffd15f6a71951a 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -307,7 +307,7 @@ void httpTrimTableName(char *name) { for (int i = 0; name[i] != 0; i++) { if (name[i] == ' ' || name[i] == ':' || name[i] == '.' || name[i] == '-' || name[i] == '/' || name[i] == '\'') name[i] = '_'; - if (i == TSDB_TABLE_NAME_LEN + 1) { + if (i == TSDB_TABLE_NAME_LEN) { name[i] = 0; break; } @@ -323,7 +323,7 @@ int httpShrinkTableName(HttpContext *pContext, int pos, char *name) { len++; } - if (len < TSDB_TABLE_NAME_LEN) { + if (len < TSDB_TABLE_NAME_LEN - 1) { return pos; } diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index c6a2230bfb28fb3bffb5d760937423291190a787..945eff76112fa2db9ef34e7d5e1051870985bd0e 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -209,7 +209,7 @@ void tgParseSchemaMetric(cJSON *metric) { goto ParseEnd; } int nameLen = (int)strlen(field->valuestring); - if (nameLen == 0 || nameLen > TSDB_TABLE_NAME_LEN) { + if (nameLen == 0 || nameLen >= TSDB_TABLE_NAME_LEN) { parsedOk = false; goto ParseEnd; } @@ -409,7 +409,7 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) { httpSendErrorResp(pContext, HTTP_TG_METRIC_NAME_NULL); return false; } - if (nameLen >= TSDB_TABLE_NAME_LEN - 7) { + if (nameLen >= TSDB_TABLE_NAME_LEN - 8) { httpSendErrorResp(pContext, HTTP_TG_METRIC_NAME_LONG); return false; } @@ -498,7 +498,7 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) { return false; } - if (strlen(host->valuestring) >= TSDB_TABLE_NAME_LEN) { + if (strlen(host->valuestring) >= TSDB_TABLE_NAME_LEN - 1) { httpSendErrorResp(pContext, HTTP_TG_TABLE_SIZE); return false; } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 26502a7408610c2d274af33a575946a1244d8da6..92c23f6b8377a34876f15bd7bf9de40878c2d933 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1368,7 +1368,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order int32_t index = pSqlFuncMsg->colInfo.colIndex; if (TSDB_COL_IS_TAG(pIndex->flag)) { if (pIndex->colId == TSDB_TBNAME_COLUMN_INDEX) { // todo refactor - pCtx->inputBytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pCtx->inputBytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; pCtx->inputType = TSDB_DATA_TYPE_BINARY; } else { pCtx->inputBytes = pQuery->tagColList[index].bytes; @@ -5148,8 +5148,8 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * bytes = tDataTypeDesc[type].nSize; } else if (pExprs[i].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX && pExprs[i].base.functionId == TSDB_FUNC_TAGPRJ) { // parse the normal column type = TSDB_DATA_TYPE_BINARY; - bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - } else { + bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; + } else{ int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols); assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags || j == TSDB_TBNAME_COLUMN_INDEX); @@ -6038,7 +6038,7 @@ static void buildTagQueryResult(SQInfo* pQInfo) { for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { char* data = tsdbGetTableName(pQInfo->tsdb, &item->id); - char* dst = pQuery->sdata[j]->data + count * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); + char* dst = pQuery->sdata[j]->data + count * ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE); memcpy(dst, data, varDataTLen(data)); } else {// todo refactor int16_t type = pExprInfo[j].type; diff --git a/src/query/src/qast.c b/src/query/src/qast.c index 0a0fe56ebd6fd960e83151ba2cf86b0101280c63..1db965e8a3abb54008a955d3563dce0a2576060e 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -138,7 +138,7 @@ static tExprNode *tExprNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken memcpy(pNode->pSchema, &pSchema[i], sizeof(SSchema)); } else { pNode->pSchema->type = TSDB_DATA_TYPE_BINARY; - pNode->pSchema->bytes = TSDB_TABLE_NAME_LEN; + pNode->pSchema->bytes = TSDB_TABLE_NAME_LEN - 1; strcpy(pNode->pSchema->name, TSQL_TBNAME_L); pNode->pSchema->colId = -1; } @@ -1127,7 +1127,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { left->pSchema = pSchema; pSchema->type = TSDB_DATA_TYPE_BINARY; - pSchema->bytes = TSDB_TABLE_NAME_LEN; + pSchema->bytes = TSDB_TABLE_NAME_LEN - 1; strcpy(pSchema->name, TSQL_TBNAME_L); pSchema->colId = -1; diff --git a/src/query/src/qtsbuf.c b/src/query/src/qtsbuf.c index 555ccb7318bed924ededc0fd13cdf1a9c2345997..869299f30936bb7fd7e40a89b02c15d06f307b8d 100644 --- a/src/query/src/qtsbuf.c +++ b/src/query/src/qtsbuf.c @@ -51,7 +51,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { return NULL; } - strncpy(pTSBuf->path, path, PATH_MAX); + tstrncpy(pTSBuf->path, path, sizeof(pTSBuf->path)); pTSBuf->f = fopen(pTSBuf->path, "r+"); if (pTSBuf->f == NULL) { diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index b0a5a0bfc0d2c53aec4187de265c6726494273a0..604406112717bef5b61671032cd59b8606c54e5d 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -458,7 +458,7 @@ int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo) { pInfo->clientPort = pConn->peerPort; // pInfo->serverIp = pConn->destIp; - strncpy(pInfo->user, pConn->user, sizeof(pInfo->user)); + tstrncpy(pInfo->user, pConn->user, sizeof(pInfo->user)); return 0; } diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 40e566789389a24e0a5572db5917ce4b4f1b6b45..8eb259d38c67afcee12be882873968f7facbaea3 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -334,7 +334,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { pTable->schema[0] = tdDupSchema(pCfg->schema); pTable->tagSchema = tdDupSchema(pCfg->tagSchema); - tsize = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN); + tsize = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN - 1); pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1); if (pTable->name == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; @@ -355,7 +355,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { pTable->tableId.tid = pCfg->tableId.tid; pTable->lastKey = TSKEY_INITIAL_VAL; - tsize = strnlen(pCfg->name, TSDB_TABLE_NAME_LEN); + tsize = strnlen(pCfg->name, TSDB_TABLE_NAME_LEN - 1); pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1); if (pTable->name == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index b9ade9496cc7bca784fb947840ee21f3a18bb411..a7255bba73fa12ac4e99bf28b97432a90426d14d 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -2011,7 +2011,7 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { f1 = (char*) pTable1->name; f2 = (char*) pTable2->name; type = TSDB_DATA_TYPE_BINARY; - bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; } else { STColumn* pCol = schemaColAt(pTableGroupSupp->pTagSchema, colIndex); bytes = pCol->bytes; diff --git a/src/util/src/tsched.c b/src/util/src/tsched.c index 898ab7087617beb5ab2fdff99e7300952edcda82..6fc767fd3bd2e37287de1a41e5dafb43a14976af 100644 --- a/src/util/src/tsched.c +++ b/src/util/src/tsched.c @@ -15,6 +15,7 @@ #include "os.h" #include "taosdef.h" +#include "tutil.h" #include "tulog.h" #include "tsched.h" #include "ttimer.h" @@ -62,8 +63,7 @@ void *taosInitScheduler(int queueSize, int numOfThreads, const char *label) { } pSched->queueSize = queueSize; - strncpy(pSched->label, label, sizeof(pSched->label)); // fix buffer overflow - pSched->label[sizeof(pSched->label)-1] = '\0'; + tstrncpy(pSched->label, label, sizeof(pSched->label)); // fix buffer overflow pSched->fullSlot = 0; pSched->emptySlot = 0; diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index 68db574d82f3e668ced4b8895c3427640641079e..cdb2c6c0beb5ea0223fb077dde20c08a5966a294 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -552,8 +552,7 @@ void* taosTmrInit(int maxNumOfTmrs, int resolution, int longest, const char* lab return NULL; } - strncpy(ctrl->label, label, sizeof(ctrl->label)); - ctrl->label[sizeof(ctrl->label) - 1] = 0; + tstrncpy(ctrl->label, label, sizeof(ctrl->label)); tmrTrace("%s timer controller is initialized, number of timer controllers: %d.", label, numOfTmrCtrl); return ctrl; } diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index c524a615919ac6e5a7458d131c2955be9dbaeafd..92091174153d6645474f906d3cdb09243db4455f 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -582,13 +582,13 @@ bool taosGetVersionNumber(char *versionStr, int *versionNubmer) { } int taosCheckVersion(char *input_client_version, char *input_server_version, int comparedSegments) { - char client_version[64] = {0}; - char server_version[64] = {0}; + char client_version[TSDB_VERSION_LEN] = {0}; + char server_version[TSDB_VERSION_LEN] = {0}; int clientVersionNumber[4] = {0}; int serverVersionNumber[4] = {0}; - strcpy(client_version, input_client_version); - strcpy(server_version, input_server_version); + tstrncpy(client_version, input_client_version, sizeof(client_version)); + tstrncpy(server_version, input_server_version, sizeof(server_version)); if (!taosGetVersionNumber(client_version, clientVersionNumber)) { uError("invalid client version:%s", client_version); diff --git a/src/vnode/inc/vnodeInt.h b/src/vnode/inc/vnodeInt.h index 7c95e81cf54272e03d5f142726189478b93d9797..ab74e329e6dd2585cdf0634e5112b087c0aa6ffc 100644 --- a/src/vnode/inc/vnodeInt.h +++ b/src/vnode/inc/vnodeInt.h @@ -51,7 +51,7 @@ typedef struct { SSyncCfg syncCfg; SWalCfg walCfg; char *rootDir; - char db[TSDB_DB_NAME_LEN + 1]; + char db[TSDB_DB_NAME_LEN]; } SVnodeObj; int vnodeWriteToQueue(void *param, void *pHead, int type); diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 99dc658d71b7524c1880deef5eb551f833c39a7d..a157100236238e1d11ad83146930ad328a1a9f9b 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -134,3 +134,7 @@ python3 ./test.py -f query/filter.py python3 ./test.py -f query/filterCombo.py python3 ./test.py -f query/queryNormal.py python3 ./test.py -f query/queryError.py + +#stream +python3 ./test.py -f stream/stream1.py +python3 ./test.py -f stream/stream2.py diff --git a/tests/pytest/random-test/random-test-multi-threading-3.py b/tests/pytest/random-test/random-test-multi-threading-3.py index cab17c4c1a91a25db57a88d674b7b60accd55a34..91f35ea7a5b812c28711a75b91ce8faa71223d68 100644 --- a/tests/pytest/random-test/random-test-multi-threading-3.py +++ b/tests/pytest/random-test/random-test-multi-threading-3.py @@ -205,6 +205,7 @@ class Test (Thread): global written dnodesDir = tdDnodes.getDnodesRootDir() + tdDnodes.forcestop(1) dataDir = dnodesDir + '/dnode1/data/*' deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) @@ -261,7 +262,7 @@ class Test (Thread): while True: self.queryEvent.wait() tdLog.notice("third thread") - randQueryOp = random.randint(1, 9) + randQueryOp = random.randint(1, 2) queryOp.get(randQueryOp, lambda: "ERROR")() self.queryEvent.clear() self.dbEvent.clear() diff --git a/tests/pytest/random-test/random-test-multi-threading.py b/tests/pytest/random-test/random-test-multi-threading.py index 1d8a5c3c82f98ffeb5817186b78959a2e160b302..997001157e804021d465ad4a6c580ad33e5631c5 100644 --- a/tests/pytest/random-test/random-test-multi-threading.py +++ b/tests/pytest/random-test/random-test-multi-threading.py @@ -208,12 +208,12 @@ class Test (threading.Thread): global written dnodesDir = tdDnodes.getDnodesRootDir() + tdDnodes.forcestop(1) dataDir = dnodesDir + '/dnode1/data/*' deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) tdDnodes.start(1) -# tdLog.sleep(10) tdSql.prepare() last_tb = "" last_stb = "" diff --git a/tests/pytest/random-test/random-test.py b/tests/pytest/random-test/random-test.py index 855cabdeddf5c437a658f145ce2fa66415b001a3..9cfc24f4045b6f57448dce7893d30fe68944afc6 100644 --- a/tests/pytest/random-test/random-test.py +++ b/tests/pytest/random-test/random-test.py @@ -166,7 +166,8 @@ class Test: def delete_datafiles(self): tdLog.info("delete_datafiles") dnodesDir = tdDnodes.getDnodesRootDir() - dataDir = dnodesDir + '/dnode1/*' + tdDnodes.forcestop(1) + dataDir = dnodesDir + '/dnode1/data/*' deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) diff --git a/tests/pytest/regressiontest.sh b/tests/pytest/regressiontest.sh index e1d4c6348b22bb4a688d7621a3e03456d7fc8e88..61407b49e36ce1c481d35d83935989ce7015cbf5 100755 --- a/tests/pytest/regressiontest.sh +++ b/tests/pytest/regressiontest.sh @@ -131,6 +131,11 @@ python3 ./test.py -f user/pass_len.py #query python3 ./test.py -f query/filter.py -# python3 ./test.py -f query/filterCombo.py -# python3 ./test.py -f query/queryNormal.py -# python3 ./test.py -f query/queryError.py + + +#stream +python3 ./test.py -f stream/stream1.py +python3 ./test.py -f stream/stream2.py + + + diff --git a/tests/pytest/table/boundary.py b/tests/pytest/table/boundary.py index bb5e187f0dc30b8d4aedad85c27d8be0c082cb46..d9f0490ed434deb0663d02143bb33ccc2f914fc0 100644 --- a/tests/pytest/table/boundary.py +++ b/tests/pytest/table/boundary.py @@ -96,14 +96,14 @@ class TDTestCase: tdLog.notice("table name max length is %d" % maxTableNameLen) # create a super table with name exceed max length - sname = self.generateString(maxTableNameLen + 1) + sname = self.generateString(maxTableNameLen) tdLog.info("create a super table with length %d" % len(sname)) tdSql.error( "create table %s (ts timestamp, value int) tags(id int)" % sname) # create a super table with name of max length - sname = self.generateString(maxTableNameLen) + sname = self.generateString(maxTableNameLen - 1) tdLog.info("create a super table with length %d" % len(sname)) tdSql.execute( "create table %s (ts timestamp, value int) tags(id int)" % @@ -113,12 +113,12 @@ class TDTestCase: tdSql.checkRows(1) # create a child table with name exceed max length - name = self.generateString(maxTableNameLen + 1) + name = self.generateString(maxTableNameLen) tdLog.info("create a child table with length %d" % len(name)) tdSql.error("create table %s using %s tags(0)" % (name, sname)) # create a child table with name of max length - name = self.generateString(maxTableNameLen) + name = self.generateString(maxTableNameLen - 1) tdLog.info("create a child table with length %d" % len(name)) tdSql.execute("create table %s using %s tags(0)" % (name, sname)) tdSql.query('show tables') diff --git a/tests/pytest/table/tablename-boundary.py b/tests/pytest/table/tablename-boundary.py index ce843c3fe70d0ecd3438c746c5f5b5af273e4e77..6ce986c51e44209bdb68d0bebef8323a71d78d7c 100644 --- a/tests/pytest/table/tablename-boundary.py +++ b/tests/pytest/table/tablename-boundary.py @@ -18,9 +18,7 @@ class TDTestCase: tdSql.prepare() getTableNameLen = "grep -w '#define TSDB_TABLE_NAME_LEN' ../../src/inc/taosdef.h|awk '{print $3}'" - tableNameMaxLen = int( - subprocess.check_output( - getTableNameLen, shell=True)) + tableNameMaxLen = int( subprocess.check_output(getTableNameLen, shell=True)) - 1 tdLog.info("table name max length is %d" % tableNameMaxLen) chars = string.ascii_uppercase + string.ascii_lowercase tb_name = ''.join(random.choices(chars, k=tableNameMaxLen)) diff --git a/tests/script/fullGeneralSuite.sim b/tests/script/fullGeneralSuite.sim index aa32fe4008edf3369ae87bea66ffef0eeb6b27ca..a7d6707e7d66d39f446ad95ed09ee78945481c16 100644 --- a/tests/script/fullGeneralSuite.sim +++ b/tests/script/fullGeneralSuite.sim @@ -211,3 +211,15 @@ run general/vector/table_field.sim run general/vector/table_mix.sim run general/vector/table_query.sim run general/vector/table_time.sim +run general/stream/stream_1.sim +run general/stream/stream_2.sim +run general/stream/stream_3.sim +run general/stream/stream_restart.sim +run general/stream/table_1.sim +run general/stream/metrics_1.sim +run general/stream/table_n.sim +run general/stream/metrics_n.sim +run general/stream/table_del.sim +run general/stream/metrics_del.sim +run general/stream/table_replica1_vnoden.sim +run general/stream/metrics_replica1_vnoden.sim diff --git a/tests/script/regressionSuite.sim b/tests/script/regressionSuite.sim index 67f54523dfee3b09521f9e34ea8e7897979e01cf..683918ee549644b0e975e40fde94c031aeaa1ef3 100644 --- a/tests/script/regressionSuite.sim +++ b/tests/script/regressionSuite.sim @@ -211,3 +211,14 @@ run general/vector/table_field.sim run general/vector/table_mix.sim run general/vector/table_query.sim run general/vector/table_time.sim +run general/stream/stream_1.sim +run general/stream/stream_2.sim +run general/stream/stream_3.sim +run general/stream/table_1.sim +run general/stream/metrics_1.sim +run general/stream/table_n.sim +run general/stream/metrics_n.sim +run general/stream/table_del.sim +run general/stream/metrics_del.sim +run general/stream/table_replica1_vnoden.sim +run general/stream/metrics_replica1_vnoden.sim diff --git a/tests/tsim/src/simParse.c b/tests/tsim/src/simParse.c index fddda679c681e12d8dbb8bcb82315f13b718dbbe..9fea1f115b2b12b12368391172f239a32efe5d5a 100644 --- a/tests/tsim/src/simParse.c +++ b/tests/tsim/src/simParse.c @@ -165,7 +165,7 @@ SScript *simBuildScriptObj(char *fileName) { script->type = SIM_SCRIPT_TYPE_MAIN; script->numOfLines = numOfLines; - strncpy(script->fileName, fileName, MAX_FILE_NAME_LEN); + tstrncpy(script->fileName, fileName, sizeof(script->fileName)); script->optionBuffer = malloc(optionOffset); memcpy(script->optionBuffer, optionBuffer, optionOffset);