From c82eecddd03a1abecb670cfb4bd4ea62abfa7b03 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 10:14:52 +0800 Subject: [PATCH 1/6] [TD-5485]:fix memory error due to uninitialized pointer value --- src/client/src/tscParseLineProtocol.c | 1 + tests/examples/c/apitest.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index cccc81274d..98d9c3ec65 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1823,6 +1823,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { cleanup: tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code); + points = TARRAY_GET_START(lpPoints); for (int i=0; i Date: Fri, 23 Jul 2021 14:19:19 +0800 Subject: [PATCH 2/6] [TD-5484]:nchar/binary tag length exceed limit error when alter table --- src/query/src/qSqlParser.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index 874ec7b692..eb920b3e17 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -712,9 +712,8 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { } else { int32_t bytes = -(int32_t)(type->type); if (bytes > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { - // we have to postpone reporting the error because it cannot be done here - // as pField->bytes is int16_t, use 'TSDB_MAX_NCHAR_LEN + 1' to avoid overflow - bytes = TSDB_MAX_NCHAR_LEN + 1; + // overflowed. set bytes to -1 so that error can be reported + bytes = -1; } else { bytes = bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; } @@ -727,8 +726,8 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { } else { int32_t bytes = -(int32_t)(type->type); if (bytes > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) { - // refer comment for NCHAR above - bytes = TSDB_MAX_BINARY_LEN + 1; + // overflowed. set bytes to -1 so that error can be reported + bytes = -1; } else { bytes += VARSTR_HEADER_SIZE; } From 269a7cead62f13caf90fd92f60f16f3b7c33641f Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 15:50:53 +0800 Subject: [PATCH 3/6] fix error when modifing tag column causing exceed limit --- src/client/src/tscSQLParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c0627f4c31..5bd981d379 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6073,7 +6073,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { for (i = 0; i < numOfColumns; ++i) { nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; } - if (nLen >= TSDB_MAX_BYTES_PER_ROW) { + if (nLen >= TSDB_MAX_TAGS_LEN) { return invalidOperationMsg(pMsg, msg24); } From 6b8e149d50cddd87831da1628f0cc5ef9cd02554 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 15:53:15 +0800 Subject: [PATCH 4/6] fix uninitialized varaible usage --- src/client/src/tscParseLineProtocol.c | 1 + src/client/src/tscSQLParser.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 98d9c3ec65..e0aa2b4327 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1824,6 +1824,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { cleanup: tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code); points = TARRAY_GET_START(lpPoints); + numPoints = taosArrayGetSize(lpPoints); for (int i=0; ipTableMeta->schema; - int16_t numOfColumns = pTableMetaInfo->pTableMeta->tableInfo.numOfColumns; + SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); + int16_t numOfTags = tscGetNumOfTags(pTableMetaInfo->pTableMeta); int16_t i; uint32_t nLen = 0; - for (i = 0; i < numOfColumns; ++i) { + for (i = 0; i < numOfTags; ++i) { nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_TAGS_LEN) { From b04048091f115fba76db79e69d74e9640d2e31bb Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 15:53:15 +0800 Subject: [PATCH 5/6] [TD-5484]:fix tag column modify total length check that checked columns instead of tags --- src/client/src/tscParseLineProtocol.c | 1 + src/client/src/tscSQLParser.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 98d9c3ec65..e0aa2b4327 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1824,6 +1824,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { cleanup: tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code); points = TARRAY_GET_START(lpPoints); + numPoints = taosArrayGetSize(lpPoints); for (int i=0; ipTableMeta->schema; - int16_t numOfColumns = pTableMetaInfo->pTableMeta->tableInfo.numOfColumns; + SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); + int16_t numOfTags = tscGetNumOfTags(pTableMetaInfo->pTableMeta); int16_t i; uint32_t nLen = 0; - for (i = 0; i < numOfColumns; ++i) { + for (i = 0; i < numOfTags; ++i) { nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_TAGS_LEN) { From 9ec1f11741034bfa870b5ac91d26918dda4ca836 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 18:21:25 +0800 Subject: [PATCH 6/6] fix error of total tags length and total columns length --- src/client/src/tscSQLParser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 39b1a5e8d3..9a3b36895d 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6020,7 +6020,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int16_t i; uint32_t nLen = 0; for (i = 0; i < numOfColumns; ++i) { - nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; + nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_BYTES_PER_ROW) { return invalidOperationMsg(pMsg, msg24); @@ -6071,7 +6071,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int16_t i; uint32_t nLen = 0; for (i = 0; i < numOfTags; ++i) { - nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; + nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_TAGS_LEN) { return invalidOperationMsg(pMsg, msg24);