From c95e314896a89dca7c4d65ecf07a004a08526fb6 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 12 May 2023 19:43:16 +0800 Subject: [PATCH] feat:[TD-23117] fix overflow in stack & add test case --- source/dnode/mnode/impl/src/mndTopic.c | 4 +++- tests/system-test/7-tmq/ins_topics_test.py | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index b3f7176a93..95524c0323 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -908,13 +908,14 @@ static int32_t mndRetrieveTopic(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataSetVal(pColInfo, numOfRows, (const char *)sql, false); - char schemaJson[TSDB_SHOW_SCHEMA_JSON_LEN + VARSTR_HEADER_SIZE] = {0}; + char *schemaJson = taosMemoryMalloc(TSDB_SHOW_SCHEMA_JSON_LEN + VARSTR_HEADER_SIZE); if(pTopic->subType == TOPIC_SUB_TYPE__COLUMN){ schemaToJson(pTopic->schema.pSchema, pTopic->schema.nCols, schemaJson); }else if(pTopic->subType == TOPIC_SUB_TYPE__TABLE){ SStbObj *pStb = mndAcquireStb(pMnode, pTopic->stbName); if (pStb == NULL) { terrno = TSDB_CODE_MND_STB_NOT_EXIST; + taosMemoryFree(schemaJson); return -1; } schemaToJson(pStb->pColumns, pStb->numOfColumns, schemaJson); @@ -926,6 +927,7 @@ static int32_t mndRetrieveTopic(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataSetVal(pColInfo, numOfRows, (const char *)schemaJson, false); + taosMemoryFree(schemaJson); char mete[4 + VARSTR_HEADER_SIZE] = {0}; if(pTopic->withMeta){ diff --git a/tests/system-test/7-tmq/ins_topics_test.py b/tests/system-test/7-tmq/ins_topics_test.py index 54b6c141f5..8bf0a7e91a 100644 --- a/tests/system-test/7-tmq/ins_topics_test.py +++ b/tests/system-test/7-tmq/ins_topics_test.py @@ -35,16 +35,24 @@ class TDTestCase: tdLog.info("create topic") tdSql.execute("create topic topic_1 as database db1") - tdSql.execute("create topic topic_2 as stable db1.st") + tdSql.execute("create topic topic_2 with meta as stable db1.st") tdSql.execute("create topic topic_3 as select * from db1.nt") - tdSql.execute("create topic topic_4 as select ts,c3,c5 from db1.st") + tdSql.execute("create topic topic_4 as select ts,c3,c5,t2 from db1.st") - tdSql.query("select * from information_schema.ins_topics") + tdSql.query("select * from information_schema.ins_topics order by topic_name") tdSql.checkRows(4) - # tdSql.checkData(0, 1, 51) - # tdSql.checkData(0, 4, 940) - # tdSql.checkData(1, 1, 23) - # tdSql.checkData(1, 4, None) + tdSql.checkData(0, 4, "NULL") + tdSql.checkData(0, 5, "no") + tdSql.checkData(0, 6, "db") + tdSql.checkData(1, 4, "[{\"name\":\"ts\",\"type\":\"TIMESTAMP\",\"length\":8},{\"name\":\"c1\",\"type\":\"INT\",\"length\":4},{\"name\":\"c2\",\"type\":\"BOOL\",\"length\":1},{\"name\":\"c3\",\"type\":\"TINYINT\",\"length\":1},{\"name\":\"c4\",\"type\":\"DOUBLE\",\"length\":8},{\"name\":\"c5\",\"type\":\"NCHAR\",\"length\":8}]") + tdSql.checkData(1, 5, "yes") + tdSql.checkData(1, 6, "stable") + tdSql.checkData(2, 4, "[{\"name\":\"ts\",\"type\":\"TIMESTAMP\",\"length\":8},{\"name\":\"c1\",\"type\":\"SMALLINT\",\"length\":2},{\"name\":\"c2\",\"type\":\"FLOAT\",\"length\":4},{\"name\":\"c3\",\"type\":\"VARCHAR\",\"length\":64},{\"name\":\"c4\",\"type\":\"BIGINT\",\"length\":8}]") + tdSql.checkData(2, 5, "no") + tdSql.checkData(2, 6, "column") + tdSql.checkData(3, 4, "[{\"name\":\"ts\",\"type\":\"TIMESTAMP\",\"length\":8},{\"name\":\"c3\",\"type\":\"TINYINT\",\"length\":1},{\"name\":\"c5\",\"type\":\"NCHAR\",\"length\":8},{\"name\":\"t2\",\"type\":\"FLOAT\",\"length\":4}]") + tdSql.checkData(3, 5, "no") + tdSql.checkData(3, 6, "column") tdLog.printNoPrefix("======== test case end ...... ")