From 6dd86242ee8586c0cea8435cff0f99ee352f36d5 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Wed, 1 Dec 2021 16:24:56 +0800 Subject: [PATCH] fix escape string values with single quote --- src/client/src/tscUtil.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 94b4b45eda..3ca15b8a0b 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -89,15 +89,34 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le break; case TSDB_DATA_TYPE_BINARY: + if (bufSize < 0) { + tscError("invalid buf size"); + return TSDB_CODE_TSC_INVALID_VALUE; + } + int32_t escapeSize = 0; + *str++ = '\''; + ++escapeSize; + char* data = buf; + for (int32_t i = 0; i < bufSize; ++i) { + if (data[i] == '\'' || data[i] == '"') { + *str++ = '\\'; + ++escapeSize; + } + *str++ = data[i]; + } + *str = '\''; + ++escapeSize; + n = bufSize + escapeSize; + break; case TSDB_DATA_TYPE_NCHAR: if (bufSize < 0) { tscError("invalid buf size"); return TSDB_CODE_TSC_INVALID_VALUE; } - *str = '"'; + *str = '\''; memcpy(str + 1, buf, bufSize); - *(str + bufSize + 1) = '"'; + *(str + bufSize + 1) = '\''; n = bufSize + 2; break; -- GitLab