提交 3fb2476e 编写于 作者: S shenglian zhou

fix: core caused by memory address changed during set db.table tag

上级 83e68782
...@@ -7339,18 +7339,19 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -7339,18 +7339,19 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
bool dbIncluded = false; bool dbIncluded = false;
SStrToken tmpToken = pAlterSQL->name; SStrToken tmpToken = pAlterSQL->name;
tmpToken.z= strndup(pAlterSQL->name.z, pAlterSQL->name.n); char* z0 = strndup(pAlterSQL->name.z, pAlterSQL->name.n);
tmpToken.z = z0;
if (tscValidateName(&tmpToken, true, &dbIncluded) != TSDB_CODE_SUCCESS) { if (tscValidateName(&tmpToken, true, &dbIncluded) != TSDB_CODE_SUCCESS) {
free(tmpToken.z); free(z0);
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
code = tscSetTableFullName(&pTableMetaInfo->name, &tmpToken, pSql, dbIncluded); code = tscSetTableFullName(&pTableMetaInfo->name, &tmpToken, pSql, dbIncluded);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
free(tmpToken.z); free(z0);
return code; return code;
} }
free(tmpToken.z); free(z0);
code = tscGetTableMeta(pSql, pTableMetaInfo); code = tscGetTableMeta(pSql, pTableMetaInfo);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
......
...@@ -225,59 +225,66 @@ char *tstrstr(char *src, char *dst, bool ignoreInEsc) { ...@@ -225,59 +225,66 @@ char *tstrstr(char *src, char *dst, bool ignoreInEsc) {
} }
char* strtolower(char *dst, const char *src) { char* strtolower(char *dst, const char *src) {
if (src == NULL || dst == NULL) { int esc = 0;
return dst; char quote = 0, *p = dst, c;
}
char* const ret = dst; assert(dst != NULL);
while (*src) {
const char ch = *(src++); for (c = *src++; c; c = *src++) {
*(dst++) = (ch >= 'A' && ch <= 'Z') ? ch - 'A' + 'a' : ch; if (esc) {
esc = 0;
if (ch == '\'' || ch == '"') { } else if (quote) {
char prev = ch; if (c == '\\') {
while (*src) { esc = 1;
const char next = *(src++); } else if (c == quote) {
*(dst++) = next; quote = 0;
if (prev != '\\' && next == ch) break;
prev = next;
}
} else if (ch == '`') {
while (*src) {
const char next = *(src++);
*(dst++) = next;
if (next == ch) break;
} }
} else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 'a';
} else if (c == '\'' || c == '"') {
quote = c;
} }
*p++ = c;
} }
*(dst) = 0;
return ret; *p = 0;
return dst;
} }
char* strntolower(char *dst, const char *src, int32_t n) { char* strntolower(char *dst, const char *src, int32_t n) {
int esc = 0, inEsc = 0;
char quote = 0, *p = dst, c;
assert(dst != NULL); assert(dst != NULL);
char* const end = dst + n; if (n == 0) {
while (dst != end) { *p = 0;
const char ch = *(src++); return dst;
*(dst++) = (ch >= 'A' && ch <= 'Z') ? ch - 'A' + 'a' : ch; }
for (c = *src++; n-- > 0; c = *src++) {
if (ch == '\'' || ch == '"') { if (esc) {
char prev = ch; esc = 0;
while (dst != end) { } else if (quote) {
const char next = *(src++); if (c == '\\') {
*(dst++) = next; esc = 1;
if (prev != '\\' && next == ch) break; } else if (c == quote) {
prev = next; quote = 0;
} }
} else if (ch == '`') { } else if (inEsc) {
while (dst != end) { if (c == '`') {
const char next = *(src++); inEsc = 0;
*(dst++) = next;
if (next == ch) break;
} }
} else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 'a';
} else if (inEsc == 0 && (c == '\'' || c == '"')) {
quote = c;
} else if (c == '`' && quote == 0) {
inEsc = 1;
} }
*p++ = c;
} }
*(dst) = 0;
return dst - n; *p = 0;
return dst;
} }
char* strntolower_s(char *dst, const char *src, int32_t n) { char* strntolower_s(char *dst, const char *src, int32_t n) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册