From 7c008851e13814c0f494d7d8fa12008ca02c85ea Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 22 Jan 2021 00:34:37 +0000 Subject: [PATCH 1/3] TD-2850 --- src/client/src/tscSQLParser.c | 1 + src/client/src/tscUtil.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ec699408de..4811a3b35d 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5427,6 +5427,7 @@ int32_t validateColumnName(char* name) { if (token.type == TK_STRING) { strdequote(token.z); + strntolower(token.z, token.z, token.n); token.n = (uint32_t)strtrim(token.z); int32_t k = tSQLGetToken(token.z, &token.type); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index d045000e24..bad4a870d5 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1420,9 +1420,11 @@ int32_t tscValidateName(SStrToken* pToken) { char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); if (sep == NULL) { // single part if (pToken->type == TK_STRING) { + strdequote(pToken->z); + strntolower(pToken->z, pToken->z, pToken->n); pToken->n = (uint32_t)strtrim(pToken->z); - + int len = tSQLGetToken(pToken->z, &pToken->type); // single token, validate it From da00ccd0f19bfee4664b21172e4586dd83afb578 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 22 Jan 2021 12:21:21 +0000 Subject: [PATCH 2/3] validate failed --- src/client/src/tscUtil.c | 4 ++++ tests/script/general/parser/dbtbnameValidate.sim | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index bad4a870d5..f33e1e292e 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1476,6 +1476,8 @@ int32_t tscValidateName(SStrToken* pToken) { if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_SQL; } + + strntolower(pToken->z, pToken->z, pToken->n); // re-build the whole name string if (pStr[firstPartLen] == TS_PATH_DELIMITER[0]) { @@ -1488,6 +1490,8 @@ int32_t tscValidateName(SStrToken* pToken) { } pToken->n += (firstPartLen + sizeof(TS_PATH_DELIMITER[0])); pToken->z = pStr; + + strntolower(pToken->z, pToken->z, pToken->n); } return TSDB_CODE_SUCCESS; diff --git a/tests/script/general/parser/dbtbnameValidate.sim b/tests/script/general/parser/dbtbnameValidate.sim index 072fd740d4..48c5d4a1f9 100644 --- a/tests/script/general/parser/dbtbnameValidate.sim +++ b/tests/script/general/parser/dbtbnameValidate.sim @@ -26,11 +26,11 @@ sql use ' XYZ ' sql drop database 'abc123' sql drop database '_ab1234' -sql drop database 'ABC123' +sql_error drop database 'ABC123' sql drop database '_ABC123' sql drop database 'aABb123' sql drop database ' xyz ' -sql drop database ' XYZ ' +sql_error drop database ' XYZ ' sql use abc @@ -67,9 +67,9 @@ sql describe mt sql describe sub_001 sql describe sub_dy_tbl -sql_error describe Dd -sql_error describe FF -sql_error describe gG +sql describe Dd +sql describe FF +sql describe gG sql drop table abc.cc sql drop table 'abc.Dd' @@ -119,4 +119,4 @@ if $rows != 4 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT From 647a679fa078a5552513204f161e8aabd20fe260 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 22 Jan 2021 13:42:17 +0000 Subject: [PATCH 3/3] failed at some case --- src/client/src/tscUtil.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index f33e1e292e..c46662097b 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -32,6 +32,14 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo); static void clearAllTableMetaInfo(SQueryInfo* pQueryInfo); +static void tscStrToLower(char *str, int32_t n) { + if (str == NULL || n <= 0) { return;} + for (int32_t i = 0; i < n; i++) { + if (str[i] >= 'A' && str[i] <= 'Z') { + str[i] -= ('A' - 'a'); + } + } +} SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) { if (pTagCond->pCond == NULL) { return NULL; @@ -1422,7 +1430,7 @@ int32_t tscValidateName(SStrToken* pToken) { if (pToken->type == TK_STRING) { strdequote(pToken->z); - strntolower(pToken->z, pToken->z, pToken->n); + tscStrToLower(pToken->z, pToken->n); pToken->n = (uint32_t)strtrim(pToken->z); int len = tSQLGetToken(pToken->z, &pToken->type); @@ -1477,8 +1485,6 @@ int32_t tscValidateName(SStrToken* pToken) { return TSDB_CODE_TSC_INVALID_SQL; } - strntolower(pToken->z, pToken->z, pToken->n); - // re-build the whole name string if (pStr[firstPartLen] == TS_PATH_DELIMITER[0]) { // first part do not have quote do nothing @@ -1491,7 +1497,7 @@ int32_t tscValidateName(SStrToken* pToken) { pToken->n += (firstPartLen + sizeof(TS_PATH_DELIMITER[0])); pToken->z = pStr; - strntolower(pToken->z, pToken->z, pToken->n); + tscStrToLower(pToken->z,pToken->n); } return TSDB_CODE_SUCCESS;