From 350c22c802035fdf44980cf108ed0d6813837e24 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 31 Aug 2021 14:41:27 +0800 Subject: [PATCH] [TD-5466] enhance like pattern --- src/client/src/tscSQLParser.c | 15 +++++++++++++-- src/kit/shell/src/shellEngine.c | 8 ++++++-- src/util/src/tcompare.c | 1 + src/util/src/tsocket.c | 2 +- src/util/src/tutil.c | 13 ++++++++----- tests/script/fullGeneralSuite.sim | 1 + 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index da5bd7d3cc..0bcddcf5f8 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -431,6 +431,7 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { const char *msg2 = "path is too long"; const char *msg3 = "invalid outputtype"; const char *msg4 = "invalid script"; + const char *msg5 = "invalid dyn lib"; SSqlCmd *pCmd = &pSql->cmd; switch (pInfo->type) { @@ -444,6 +445,10 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { } createInfo->name.z[createInfo->name.n] = 0; + // funcname's naming rule is same to column + if (validateColumnName(createInfo->name.z) != TSDB_CODE_SUCCESS) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + } strdequote(createInfo->name.z); @@ -463,10 +468,16 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (ret) { return ret; } - //distinguish *.lua and *.so + //validate *.lua or .so int32_t pathLen = (int32_t)strlen(createInfo->path.z); - if ((pathLen > 3) && (0 == strncmp(createInfo->path.z + pathLen - 3, "lua", 3)) && !isValidScript(buf, len)) { + if ((pathLen > 4) && (0 == strncmp(createInfo->path.z + pathLen - 4, ".lua", 4)) && !isValidScript(buf, len)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + } else if (pathLen > 3 && (0 == strncmp(createInfo->path.z + pathLen - 3, ".so", 3))) { + void *handle = taosLoadDll(createInfo->path.z); + taosCloseDll(handle); + if (handle == NULL) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); + } } //TODO CHECK CODE diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 51a25d59c4..ef3a2458a0 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -255,8 +255,12 @@ int32_t shellRunCommand(TAOS* con, char* command) { } if (c == '\\') { - esc = true; - continue; + if (quote != 0 && (*command == '_' || *command == '\\')) { + //DO nothing + } else { + esc = true; + continue; + } } if (quote == c) { diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 1b980a4a1d..47cc751318 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -262,6 +262,7 @@ int patternMatch(const char *patterStr, const char *str, size_t size, const SPat c1 = str[j++]; if (j <= size) { + if (c == '\\' && patterStr[i] == '_' && c1 == '_') { i++; continue; } if (c == c1 || tolower(c) == tolower(c1) || (c == pInfo->matchOne && c1 != 0)) { continue; } diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index 77941cba82..8d69a87e77 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -488,7 +488,7 @@ SOCKET taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { return -1; } - if (listen(sockFd, 10) < 0) { + if (listen(sockFd, 1024) < 0) { uError("listen tcp server socket failed, 0x%x:%hu(%s)", ip, port, strerror(errno)); taosCloseSocket(sockFd); return -1; diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index f8a97ff7cd..ae10dd265a 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -64,12 +64,15 @@ int32_t strRmquote(char *z, int32_t len){ int32_t j = 0; for (uint32_t k = 1; k < len - 1; ++k) { if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) { + if (z[k] == '\\' && z[k + 1] == '_') { + //match '_' self + } else { z[j] = z[k + 1]; - - cnt++; - j++; - k++; - continue; + cnt++; + j++; + k++; + continue; + } } z[j] = z[k]; diff --git a/tests/script/fullGeneralSuite.sim b/tests/script/fullGeneralSuite.sim index 5b5a911558..9f46b07847 100644 --- a/tests/script/fullGeneralSuite.sim +++ b/tests/script/fullGeneralSuite.sim @@ -221,3 +221,4 @@ run general/stream/table_replica1_vnoden.sim run general/stream/metrics_replica1_vnoden.sim run general/db/show_create_db.sim run general/db/show_create_table.sim +run general/parser/like.sim -- GitLab