diff --git a/deps/cJson/inc/cJSON.h b/deps/cJson/inc/cJSON.h index cdd5faa52399e83dd2c07174a025eae52a3c1b61..6b9faac0333d6a893551d87292083ed04d9a378e 100644 --- a/deps/cJson/inc/cJSON.h +++ b/deps/cJson/inc/cJSON.h @@ -73,7 +73,7 @@ typedef struct cJSON char *string; //Keep the original string of number - char numberstring[13]; + char numberstring[22]; /* change this to 22 bytes to accommodate LLONG_MAX and LLONG_MINX*/ } cJSON; typedef struct cJSON_Hooks diff --git a/deps/cJson/src/cJSON.c b/deps/cJson/src/cJSON.c index f0ef9f6fe1715336ed8d24d4998df5a8ba51b3af..ff93e8730d4e9b378efaa5c9039eb886e3a30e97 100644 --- a/deps/cJson/src/cJSON.c +++ b/deps/cJson/src/cJSON.c @@ -290,7 +290,7 @@ loop_end: input_buffer->offset += (size_t)(after_end - number_c_string); - strncpy(item->numberstring, (const char *)number_c_string, 12); + strncpy(item->numberstring, (const char *)number_c_string, strlen((const char*)number_c_string)); return true; } diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index ce0932e260d0d38166638d5fe7f5a5524526ffe8..afae64727b9cdbd94104fc7646c5eb0b1d3da2fb 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -623,14 +623,19 @@ static int32_t convertJSONNumber(TAOS_SML_KV *pVal, char* typeStr, cJSON *value, //bigint if (strcasecmp(typeStr, "i64") == 0 || strcasecmp(typeStr, "bigint") == 0) { - if (!IS_VALID_BIGINT(value->valueint)) { - tscError("OTD:0x%"PRIx64" JSON value(%"PRId64") cannot fit in type(bigint)", info->id, value->valueint); - return TSDB_CODE_TSC_VALUE_OUT_OF_RANGE; - } pVal->type = TSDB_DATA_TYPE_BIGINT; pVal->length = (int16_t)tDataTypes[pVal->type].bytes; pVal->value = tcalloc(pVal->length, 1); - *(int64_t *)(pVal->value) = (int64_t)(value->valueint); + /* cJSON conversion of legit BIGINT may overflow, + * use original string to do the conversion. + */ + errno = 0; + int64_t val = (int64_t)strtoll(value->numberstring, NULL, 10); + if (errno == ERANGE || !IS_VALID_BIGINT(val)) { + tscError("OTD:0x%"PRIx64" JSON value(%s) cannot fit in type(bigint)", info->id, value->numberstring); + return TSDB_CODE_TSC_VALUE_OUT_OF_RANGE; + } + *(int64_t *)(pVal->value) = val; return TSDB_CODE_SUCCESS; } //float @@ -746,7 +751,16 @@ static int32_t parseValueFromJSON(cJSON *root, TAOS_SML_KV *pVal, SSmlLinesInfo* pVal->type = TSDB_DATA_TYPE_BIGINT; pVal->length = (int16_t)tDataTypes[pVal->type].bytes; pVal->value = tcalloc(pVal->length, 1); - *(int64_t *)(pVal->value) = (int64_t)(root->valuedouble); + /* cJSON conversion of legit BIGINT may overflow, + * use original string to do the conversion. + */ + errno = 0; + int64_t val = (int64_t)strtoll(root->numberstring, NULL, 10); + if (errno == ERANGE || !IS_VALID_BIGINT(val)) { + tscError("OTD:0x%"PRIx64" JSON value(%s) cannot fit in type(bigint)", info->id, root->numberstring); + return TSDB_CODE_TSC_VALUE_OUT_OF_RANGE; + } + *(int64_t *)(pVal->value) = val; } else if (isValidFloat(root->numberstring)) { pVal->type = TSDB_DATA_TYPE_DOUBLE; pVal->length = (int16_t)tDataTypes[pVal->type].bytes;