Skip to content

Commit

Permalink
Merge pull request #10993 from taosdata/TD-13918
Browse files Browse the repository at this point in the history
[TD-13918]<fix>: Strings are compared without comparing lengths
  • Loading branch information
stephenkgu authored Mar 25, 2022
2 parents 1eae6c0 + b2134b9 commit 1225c9a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/client/inc/tscUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void tscRemoveCachedTableMeta(STableMetaInfo* pTableMetaInfo, uint64_t id);

char* cloneCurrentDBName(SSqlObj* pSql);

int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, int16_t startColId);
int parseJsontoTagData(char* json, uint32_t jsonLength, SKVRowBuilder* kvRowBuilder, char* errMsg, int16_t startColId);
int8_t jsonType2DbType(double data, int jsonType);
void getJsonKey(SStrToken *t0);

Expand Down
2 changes: 1 addition & 1 deletion src/client/src/tscParseInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
tfree(tmp);
return tscSQLSyntaxErrMsg(pInsertParam->msg, "json tag too long", NULL);
}
code = parseJsontoTagData(sToken.z, &kvRowBuilder, pInsertParam->msg, pTagSchema[spd.boundedColumns[0]].colId);
code = parseJsontoTagData(sToken.z, sToken.n, &kvRowBuilder, pInsertParam->msg, pTagSchema[spd.boundedColumns[0]].colId);
if (code != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder);
tscDestroyBoundColumnInfo(&spd);
Expand Down
4 changes: 2 additions & 2 deletions src/client/src/tscSQLParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6955,7 +6955,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int8_t tagVal = TSDB_DATA_JSON_PLACEHOLDER;
tdAddColToKVRow(&kvRowBuilder, pTagsSchema->colId, pTagsSchema->type, &tagVal, false);

code = parseJsontoTagData(pItem->pVar.pz, &kvRowBuilder, pMsg, pTagsSchema->colId);
code = parseJsontoTagData(pItem->pVar.pz, pItem->pVar.nLen, &kvRowBuilder, pMsg, pTagsSchema->colId);
if (code != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder);
return code;
Expand Down Expand Up @@ -8767,7 +8767,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}

ret = parseJsontoTagData(pItem->pVar.pz, &kvRowBuilder, tscGetErrorMsgPayload(pCmd), pTagSchema[0].colId);
ret = parseJsontoTagData(pItem->pVar.pz, pItem->pVar.nLen, &kvRowBuilder, tscGetErrorMsgPayload(pCmd), pTagSchema[0].colId);
if (ret != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder);
return ret;
Expand Down
4 changes: 2 additions & 2 deletions src/client/src/tscUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -5378,7 +5378,7 @@ char* cloneCurrentDBName(SSqlObj* pSql) {
return p;
}

int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, int16_t startColId){
int parseJsontoTagData(char* json, uint32_t jsonLength, SKVRowBuilder* kvRowBuilder, char* errMsg, int16_t startColId){
// set json NULL data
uint8_t nullTypeVal[CHAR_BYTES + VARSTR_HEADER_SIZE + INT_BYTES] = {0};
uint32_t jsonNULL = TSDB_DATA_JSON_NULL;
Expand All @@ -5389,7 +5389,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
varDataSetLen(nullTypeVal + CHAR_BYTES, INT_BYTES);
*(uint32_t*)(varDataVal(nullTypeKey)) = jsonNULL;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, nullTypeKey, false); // add json null type
if (!json || strtrim(json) == 0 || strncasecmp(json, "null", 4) == 0){
if (!json || strtrim(json) == 0 || (jsonLength == strlen("null") && strncasecmp(json, "null", 4) == 0)){
*(uint32_t*)(varDataVal(nullTypeVal + CHAR_BYTES)) = jsonNULL;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, nullTypeVal, true); // add json null value
return TSDB_CODE_SUCCESS;
Expand Down
20 changes: 20 additions & 0 deletions tests/develop-test/0-others/json_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,26 @@ def run(self):
tdSql.checkData(5, 2, 4096)
tdSql.query("describe jsons1_1")
tdSql.checkData(5, 2, 4096)

#test TD-13918
tdSql.execute("drop table if exists jsons_13918_1")
tdSql.execute("drop table if exists jsons_13918_2")
tdSql.execute("drop table if exists jsons_13918_3")
tdSql.execute("drop table if exists jsons_13918_4")
tdSql.execute("drop table if exists jsons_stb")
tdSql.execute("create table jsons_stb (ts timestamp, dataInt int) tags (jtag json)")
tdSql.error("create table jsons_13918_1 using jsons_stb tags ('nullx')")
tdSql.error("create table jsons_13918_2 using jsons_stb tags (nullx)")
tdSql.error("insert into jsons_13918_3 using jsons_stb tags('NULLx') values(1591061628001, 11)")
tdSql.error("insert into jsons_13918_4 using jsons_stb tags(NULLx) values(1591061628002, 11)")
tdSql.execute("create table jsons_13918_1 using jsons_stb tags ('null')")
tdSql.execute("create table jsons_13918_2 using jsons_stb tags (null)")
tdSql.execute("insert into jsons_13918_1 values(1591061628003, 11)")
tdSql.execute("insert into jsons_13918_2 values(1591061628004, 11)")
tdSql.execute("insert into jsons_13918_3 using jsons_stb tags('NULL') values(1591061628005, 11)")
tdSql.execute("insert into jsons_13918_4 using jsons_stb tags(\"NULL\") values(1591061628006, 11)")
tdSql.query("select * from jsons_stb")
tdSql.checkRows(4)

def stop(self):
tdSql.close()
Expand Down

0 comments on commit 1225c9a

Please sign in to comment.