From 8f9a77279d05ee6d25fef802358d1335e94e7bcb Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Sun, 26 Sep 2021 16:39:41 +0800 Subject: [PATCH] [TD-10491]: Unified schemaless table name length(<=192) and column name length(<=64) boundaries. --- src/client/inc/tscParseLine.h | 2 +- src/client/src/tscParseLineProtocol.c | 16 ++++++++++------ src/client/src/tscParseOpenTSDB.c | 24 ++++++++++++++---------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/client/inc/tscParseLine.h b/src/client/inc/tscParseLine.h index 6204035996..8c7aaad81b 100644 --- a/src/client/inc/tscParseLine.h +++ b/src/client/inc/tscParseLine.h @@ -63,7 +63,7 @@ bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlLinesInfo* info); bool isValidInteger(char *str); bool isValidFloat(char *str); -int32_t isValidChildTableName(const char *pTbName, int16_t len); +int32_t isValidChildTableName(const char *pTbName, int16_t len, SSmlLinesInfo* info); bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, uint16_t len, SSmlLinesInfo* info); diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 53b0b4dc93..f9c994d1cb 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1811,8 +1811,8 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; } while (*cur != '\0') { - if (len > TSDB_COL_NAME_LEN) { - tscError("SML:0x%"PRIx64" Key field cannot exceeds 65 characters", info->id); + if (len > TSDB_COL_NAME_LEN - 1) { + tscError("SML:0x%"PRIx64" Key field cannot exceeds 64 characters", info->id); return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; } //unescaped '=' identifies a tag key @@ -1898,8 +1898,8 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index } while (*cur != '\0') { - if (len > TSDB_TABLE_NAME_LEN) { - tscError("SML:0x%"PRIx64" Measurement field cannot exceeds 193 characters", info->id); + if (len > TSDB_TABLE_NAME_LEN - 1) { + tscError("SML:0x%"PRIx64" Measurement field cannot exceeds 192 characters", info->id); free(pSml->stableName); pSml->stableName = NULL; return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; @@ -1929,7 +1929,11 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index } //Table name can only contain digits(0-9),alphebet(a-z),underscore(_) -int32_t isValidChildTableName(const char *pTbName, int16_t len) { +int32_t isValidChildTableName(const char *pTbName, int16_t len, SSmlLinesInfo* info) { + if (len > TSDB_TABLE_NAME_LEN - 1) { + tscError("SML:0x%"PRIx64" child table name cannot exceeds 192 characters", info->id); + return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; + } const char *cur = pTbName; for (int i = 0; i < len; ++i) { if(!isdigit(cur[i]) && !isalpha(cur[i]) && (cur[i] != '_')) { @@ -1975,7 +1979,7 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs, } if (!isField && (strcasecmp(pkv->key, "ID") == 0) && pkv->type == TSDB_DATA_TYPE_BINARY) { - ret = isValidChildTableName(pkv->value, pkv->length); + ret = isValidChildTableName(pkv->value, pkv->length, info); if (ret) { goto error; } diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index ecfc619f8a..39301f1189 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -37,7 +37,7 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, const char *cur = *index; uint16_t len = 0; - pSml->stableName = tcalloc(TSDB_TABLE_NAME_LEN + 1, 1); // +1 to avoid 1772 line over write + pSml->stableName = tcalloc(TSDB_TABLE_NAME_LEN, 1); if (pSml->stableName == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -48,8 +48,8 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, } while (*cur != '\0') { - if (len > TSDB_TABLE_NAME_LEN) { - tscError("OTD:0x%"PRIx64" Metric cannot exceeds 193 characters", info->id); + if (len > TSDB_TABLE_NAME_LEN - 1) { + tscError("OTD:0x%"PRIx64" Metric cannot exceeds 192 characters", info->id); tfree(pSml->stableName); return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; } @@ -171,7 +171,7 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch static int32_t parseTelnetTagKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash, SSmlLinesInfo* info) { const char *cur = *index; - char key[TSDB_COL_NAME_LEN + 1]; // +1 to avoid key[len] over write + char key[TSDB_COL_NAME_LEN]; uint16_t len = 0; //key field cannot start with digit @@ -180,8 +180,8 @@ static int32_t parseTelnetTagKey(TAOS_SML_KV *pKV, const char **index, SHashObj return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; } while (*cur != '\0') { - if (len > TSDB_COL_NAME_LEN) { - tscError("OTD:0x%"PRIx64" Tag key cannot exceeds 65 characters", info->id); + if (len > TSDB_COL_NAME_LEN - 1) { + tscError("OTD:0x%"PRIx64" Tag key cannot exceeds 64 characters", info->id); return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; } if (*cur == ' ') { @@ -276,7 +276,7 @@ static int32_t parseTelnetTagKvs(TAOS_SML_KV **pKVs, int *num_kvs, return ret; } if ((strcasecmp(pkv->key, "ID") == 0) && pkv->type == TSDB_DATA_TYPE_BINARY) { - ret = isValidChildTableName(pkv->value, pkv->length); + ret = isValidChildTableName(pkv->value, pkv->length, info); if (ret) { return ret; } @@ -446,8 +446,8 @@ static int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlL } size_t stableLen = strlen(metric->valuestring); - if (stableLen > TSDB_TABLE_NAME_LEN) { - tscError("OTD:0x%"PRIx64" Metric cannot exceeds 193 characters in JSON", info->id); + if (stableLen > TSDB_TABLE_NAME_LEN - 1) { + tscError("OTD:0x%"PRIx64" Metric cannot exceeds 192 characters in JSON", info->id); return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; } @@ -843,7 +843,7 @@ static int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs, cJSON *id = cJSON_GetObjectItem(tags, "ID"); if (id != NULL) { size_t idLen = strlen(id->valuestring); - ret = isValidChildTableName(id->valuestring, (int16_t)idLen); + ret = isValidChildTableName(id->valuestring, (int16_t)idLen, info); if (ret != TSDB_CODE_SUCCESS) { return ret; } @@ -880,6 +880,10 @@ static int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs, } //key size_t keyLen = strlen(tag->string); + if (keyLen > TSDB_COL_NAME_LEN - 1) { + tscError("OTD:0x%"PRIx64" Tag key cannot exceeds 64 characters in JSON", info->id); + return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; + } pkv->key = tcalloc(keyLen + 1, sizeof(char)); strncpy(pkv->key, tag->string, keyLen); //value -- GitLab