Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1da9c4c9
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1da9c4c9
编写于
7月 23, 2021
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-5451]<fix> add integer&float boundary check
上级
09e32005
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
133 addition
and
42 deletion
+133
-42
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+131
-42
src/inc/ttype.h
src/inc/ttype.h
+2
-0
未找到文件。
src/client/src/tscParseLineProtocol.c
浏览文件 @
1da9c4c9
...
...
@@ -1217,6 +1217,122 @@ static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType) {
return
false
;
}
static
bool
convertStrToNumber
(
TAOS_SML_KV
*
pVal
,
char
*
str
)
{
errno
=
0
;
uint8_t
type
=
pVal
->
type
;
int16_t
length
=
pVal
->
length
;
int64_t
val_s
;
uint64_t
val_u
;
double
val_d
;
printf
(
"origin str:%s
\n
"
,
str
);
if
(
IS_FLOAT_TYPE
(
type
))
{
val_d
=
strtod
(
str
,
NULL
);
}
else
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
type
))
{
val_s
=
strtoll
(
str
,
NULL
,
10
);
}
else
{
val_u
=
strtoull
(
str
,
NULL
,
10
);
}
}
if
(
errno
==
ERANGE
)
{
printf
(
"out of range
\n
"
);
return
false
;
}
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
if
(
!
IS_VALID_TINYINT
(
val_s
))
{
printf
(
"tiny int out of range
\n
"
);
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
int8_t
*
)(
pVal
->
value
)
=
(
int8_t
)
val_s
;
printf
(
"tiny int:%d
\n
"
,
*
(
int8_t
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
if
(
!
IS_VALID_UTINYINT
(
val_u
))
{
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
uint8_t
*
)(
pVal
->
value
)
=
(
uint8_t
)
val_u
;
printf
(
"tiny uint:%u
\n
"
,
*
(
uint8_t
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
if
(
!
IS_VALID_SMALLINT
(
val_s
))
{
printf
(
"small int out of range
\n
"
);
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
int16_t
*
)(
pVal
->
value
)
=
(
int16_t
)
val_s
;
printf
(
"small int:%d
\n
"
,
*
(
int16_t
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
if
(
!
IS_VALID_USMALLINT
(
val_u
))
{
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
uint16_t
*
)(
pVal
->
value
)
=
(
uint16_t
)
val_u
;
printf
(
"small uint:%u
\n
"
,
*
(
uint16_t
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_INT
:
if
(
!
IS_VALID_INT
(
val_s
))
{
printf
(
"int out of range
\n
"
);
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
int32_t
*
)(
pVal
->
value
)
=
(
int32_t
)
val_s
;
printf
(
"int:%d
\n
"
,
*
(
int32_t
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_UINT
:
if
(
!
IS_VALID_UINT
(
val_u
))
{
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
uint32_t
*
)(
pVal
->
value
)
=
(
uint32_t
)
val_u
;
printf
(
"uint:%u
\n
"
,
*
(
uint32_t
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_BIGINT
:
if
(
!
IS_VALID_BIGINT
(
val_s
))
{
printf
(
"big int out of range
\n
"
);
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
int64_t
*
)(
pVal
->
value
)
=
(
int64_t
)
val_s
;
printf
(
"big int:%ld
\n
"
,
*
(
int64_t
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
if
(
!
IS_VALID_UBIGINT
(
val_u
))
{
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
uint64_t
*
)(
pVal
->
value
)
=
(
uint64_t
)
val_u
;
printf
(
"big uint:%lu
\n
"
,
*
(
uint64_t
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_FLOAT
:
if
(
!
IS_VALID_FLOAT
(
val_d
))
{
printf
(
"float out of range
\n
"
);
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
float
*
)(
pVal
->
value
)
=
(
float
)
val_d
;
printf
(
"float:%.5e
\n
"
,
*
(
float
*
)(
pVal
->
value
));
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
if
(
!
IS_VALID_DOUBLE
(
val_d
))
{
printf
(
"double out of range
\n
"
);
return
false
;
}
pVal
->
value
=
calloc
(
length
,
1
);
*
(
double
*
)(
pVal
->
value
)
=
(
double
)
val_d
;
printf
(
"double:%.5e
\n
"
,
*
(
double
*
)(
pVal
->
value
));
break
;
default:
return
false
;
}
return
true
;
}
//len does not include '\0' from value.
static
bool
convertSmlValueType
(
TAOS_SML_KV
*
pVal
,
char
*
value
,
uint16_t
len
)
{
...
...
@@ -1229,97 +1345,72 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal
->
type
=
TSDB_DATA_TYPE_TINYINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
2
]
=
'\0'
;
if
(
!
isValidInteger
(
value
))
{
if
(
!
isValidInteger
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
int8_t
val
=
(
int8_t
)
strtoll
(
value
,
NULL
,
10
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
if
(
isTinyUint
(
value
,
len
))
{
pVal
->
type
=
TSDB_DATA_TYPE_UTINYINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
2
]
=
'\0'
;
if
(
!
isValidInteger
(
value
))
{
if
(
!
isValidInteger
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
uint8_t
val
=
(
uint8_t
)
strtoul
(
value
,
NULL
,
10
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
if
(
isSmallInt
(
value
,
len
))
{
pVal
->
type
=
TSDB_DATA_TYPE_SMALLINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
3
]
=
'\0'
;
if
(
!
isValidInteger
(
value
))
{
if
(
!
isValidInteger
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
int16_t
val
=
(
int16_t
)
strtoll
(
value
,
NULL
,
10
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
if
(
isSmallUint
(
value
,
len
))
{
pVal
->
type
=
TSDB_DATA_TYPE_USMALLINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
3
]
=
'\0'
;
if
(
!
isValidInteger
(
value
))
{
if
(
!
isValidInteger
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
uint16_t
val
=
(
uint16_t
)
strtoul
(
value
,
NULL
,
10
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
//memcpy(pVal->value, &val, pVal->length);
return
true
;
}
if
(
isInt
(
value
,
len
))
{
pVal
->
type
=
TSDB_DATA_TYPE_INT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
3
]
=
'\0'
;
if
(
!
isValidInteger
(
value
))
{
if
(
!
isValidInteger
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
int32_t
val
=
(
int32_t
)
strtoll
(
value
,
NULL
,
10
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
if
(
isUint
(
value
,
len
))
{
pVal
->
type
=
TSDB_DATA_TYPE_UINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
3
]
=
'\0'
;
if
(
!
isValidInteger
(
value
))
{
if
(
!
isValidInteger
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
uint32_t
val
=
(
uint32_t
)
strtoul
(
value
,
NULL
,
10
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
if
(
isBigInt
(
value
,
len
))
{
pVal
->
type
=
TSDB_DATA_TYPE_BIGINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
3
]
=
'\0'
;
if
(
!
isValidInteger
(
value
))
{
if
(
!
isValidInteger
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
int64_t
val
=
(
int64_t
)
strtoll
(
value
,
NULL
,
10
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
if
(
isBigUint
(
value
,
len
))
{
pVal
->
type
=
TSDB_DATA_TYPE_UBIGINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
3
]
=
'\0'
;
if
(
!
isValidInteger
(
value
))
{
if
(
!
isValidInteger
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
uint64_t
val
=
(
uint64_t
)
strtoul
(
value
,
NULL
,
10
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
//floating number
...
...
@@ -1327,24 +1418,18 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal
->
type
=
TSDB_DATA_TYPE_FLOAT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
3
]
=
'\0'
;
if
(
!
isValidFloat
(
value
))
{
if
(
!
isValidFloat
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
float
val
=
(
float
)
strtold
(
value
,
NULL
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
if
(
isDouble
(
value
,
len
))
{
pVal
->
type
=
TSDB_DATA_TYPE_DOUBLE
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
value
[
len
-
3
]
=
'\0'
;
if
(
!
isValidFloat
(
value
))
{
if
(
!
isValidFloat
(
value
)
||
!
convertStrToNumber
(
pVal
,
value
)
)
{
return
false
;
}
pVal
->
value
=
calloc
(
pVal
->
length
,
1
);
double
val
=
(
double
)
strtold
(
value
,
NULL
);
memcpy
(
pVal
->
value
,
&
val
,
pVal
->
length
);
return
true
;
}
//binary
...
...
@@ -1554,6 +1639,7 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
if
(
!
convertSmlValueType
(
pKV
,
value
,
len
))
{
//free previous alocated key field
free
(
pKV
->
key
);
pKV
->
key
=
NULL
;
free
(
value
);
return
TSDB_CODE_TSC_LINE_SYNTAX_ERROR
;
}
...
...
@@ -1823,8 +1909,11 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) {
cleanup:
tscDebug
(
"taos_insert_lines finish inserting %d lines. code: %d"
,
numLines
,
code
);
numPoints
=
taosArrayGetSize
(
lpPoints
);
TAOS_SML_DATA_POINT
*
ppoints
=
TARRAY_GET_START
(
lpPoints
);
for
(
int
i
=
0
;
i
<
numPoints
;
++
i
)
{
destroySmlDataPoint
(
points
+
i
);
destroySmlDataPoint
(
p
p
oints
+
i
);
}
taosArrayDestroy
(
lpPoints
);
...
...
src/inc/ttype.h
浏览文件 @
1da9c4c9
...
...
@@ -138,6 +138,8 @@ typedef struct {
#define IS_VALID_USMALLINT(_t) ((_t) >= 0 && (_t) < UINT16_MAX)
#define IS_VALID_UINT(_t) ((_t) >= 0 && (_t) < UINT32_MAX)
#define IS_VALID_UBIGINT(_t) ((_t) >= 0 && (_t) < UINT64_MAX)
#define IS_VALID_FLOAT(_t) ((_t) >= -FLT_MAX && (_t) <= FLT_MAX)
#define IS_VALID_DOUBLE(_t) ((_t) >= -DBL_MAX && (_t) <= DBL_MAX)
static
FORCE_INLINE
bool
isNull
(
const
char
*
val
,
int32_t
type
)
{
switch
(
type
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录