提交 a0d46fe9 编写于 作者: wmmhello's avatar wmmhello

fix:json parse error

上级 326ff76f
......@@ -69,6 +69,7 @@ extern "C" {
#define VALUE "_value"
#define VALUE_LEN 6
#define OTD_JSON_FIELDS_NUM 4
#define MAX_RETRY_TIMES 5
typedef TSDB_SML_PROTOCOL_TYPE SMLProtocolType;
......@@ -178,7 +179,7 @@ typedef struct {
SSmlMsgBuf msgBuf;
cJSON *root; // for parse json
int8_t offset[4];
int8_t offset[OTD_JSON_FIELDS_NUM];
SSmlLineInfo *lines; // element is SSmlLineInfo
//
......
......@@ -20,7 +20,6 @@
#include "clientSml.h"
#define OTD_JSON_SUB_FIELDS_NUM 2
#define OTD_JSON_FIELDS_NUM 4
#define JUMP_JSON_SPACE(start) \
while(*(start)){\
......@@ -249,6 +248,11 @@ int smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset){
continue;
}
if(unlikely(index >= OTD_JSON_FIELDS_NUM)) {
uError("index >= %d, %s", OTD_JSON_FIELDS_NUM, *start)
break;
}
char *sTmp = *start;
if((*start)[1] == 'm' && (*start)[2] == 'e' && (*start)[3] == 't'
&& (*start)[4] == 'r' && (*start)[5] == 'i' && (*start)[6] == 'c' && (*start)[7] == '"'){
......@@ -353,6 +357,11 @@ int smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset){
continue;
}
if(unlikely(index >= OTD_JSON_FIELDS_NUM)) {
uError("index >= %d, %s", OTD_JSON_FIELDS_NUM, *start)
break;
}
if((*start)[1] == 'm'){
(*start) += offset[index++];
element->measure = *start;
......@@ -980,6 +989,13 @@ static int32_t smlParseJSONStringExt(SSmlHandle *info, cJSON *root, SSmlLineInfo
cJSON *valueJson = NULL;
cJSON *tagsJson = NULL;
int32_t size = cJSON_GetArraySize(root);
// outmost json fields has to be exactly 4
if (size != OTD_JSON_FIELDS_NUM) {
uError("OTD:0x%" PRIx64 " Invalid number of JSON fields in data point %d", info->id, size);
return TSDB_CODE_TSC_INVALID_JSON;
}
cJSON **marks[OTD_JSON_FIELDS_NUM] = {&metricJson, &tsJson, &valueJson, &tagsJson};
ret = smlGetJsonElements(root, marks);
if (unlikely(ret != TSDB_CODE_SUCCESS)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册