Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3ee0a36b
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3ee0a36b
编写于
1月 11, 2022
作者:
F
freemine
提交者:
GitHub
1月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
qScript: potential buffer overrun (#9728)
上级
c2d13789
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
16 deletion
+39
-16
src/query/inc/qScript.h
src/query/inc/qScript.h
+5
-2
src/query/src/qScript.c
src/query/src/qScript.c
+34
-14
未找到文件。
src/query/inc/qScript.h
浏览文件 @
3ee0a36b
...
@@ -25,10 +25,11 @@
...
@@ -25,10 +25,11 @@
#include "tlist.h"
#include "tlist.h"
#include "qUdf.h"
#include "qUdf.h"
#define MAX_FUNC_NAME 64
#define USER_FUNC_NAME "funcName"
#define USER_FUNC_NAME "funcName"
#define USER_FUNC_NAME_LIMIT 48
#define USER_FUNC_NAME_LIMIT 48
/* define in this way to let others know that these two macros are logically related */
#define MAX_FUNC_NAME (USER_FUNC_NAME_LIMIT + 16)
enum
ScriptState
{
enum
ScriptState
{
SCRIPT_STATE_INIT
,
SCRIPT_STATE_INIT
,
...
@@ -44,7 +45,9 @@ typedef struct {
...
@@ -44,7 +45,9 @@ typedef struct {
}
ScriptEnv
;
}
ScriptEnv
;
typedef
struct
ScriptCtx
{
typedef
struct
ScriptCtx
{
char
funcName
[
USER_FUNC_NAME_LIMIT
];
// one-more-space-for-null-terminator to support function name
// at most USER_FUNC_NAME_LIMIT bytes long actually
char
funcName
[
USER_FUNC_NAME_LIMIT
+
1
];
int8_t
state
;
int8_t
state
;
ScriptEnv
*
pEnv
;
ScriptEnv
*
pEnv
;
int8_t
isAgg
;
// agg function or not
int8_t
isAgg
;
// agg function or not
...
...
src/query/src/qScript.c
浏览文件 @
3ee0a36b
...
@@ -91,8 +91,12 @@ void taosValueToLuaType(lua_State *lua, int32_t type, char *val) {
...
@@ -91,8 +91,12 @@ void taosValueToLuaType(lua_State *lua, int32_t type, char *val) {
}
}
int
taosLoadScriptInit
(
void
*
pInit
)
{
int
taosLoadScriptInit
(
void
*
pInit
)
{
ScriptCtx
*
pCtx
=
pInit
;
ScriptCtx
*
pCtx
=
pInit
;
char
funcName
[
MAX_FUNC_NAME
]
=
{
0
};
char
funcName
[
MAX_FUNC_NAME
+
1
]
=
{
0
};
// one-more-space-for-null-terminator
sprintf
(
funcName
,
"%s_init"
,
pCtx
->
funcName
);
int
n
=
snprintf
(
funcName
,
sizeof
(
funcName
),
"%s_init"
,
pCtx
->
funcName
);
if
(
n
<
0
||
(
size_t
)
n
>=
sizeof
(
funcName
))
{
// FIXME: what internal error-code to set?
return
-
1
;
}
lua_State
*
lua
=
pCtx
->
pEnv
->
lua_state
;
lua_State
*
lua
=
pCtx
->
pEnv
->
lua_state
;
lua_getglobal
(
lua
,
funcName
);
lua_getglobal
(
lua
,
funcName
);
...
@@ -105,8 +109,12 @@ int taosLoadScriptInit(void* pInit) {
...
@@ -105,8 +109,12 @@ int taosLoadScriptInit(void* pInit) {
void
taosLoadScriptNormal
(
void
*
pInit
,
char
*
pInput
,
int16_t
iType
,
int16_t
iBytes
,
int32_t
numOfRows
,
void
taosLoadScriptNormal
(
void
*
pInit
,
char
*
pInput
,
int16_t
iType
,
int16_t
iBytes
,
int32_t
numOfRows
,
int64_t
*
ptsList
,
int64_t
key
,
char
*
pOutput
,
char
*
ptsOutput
,
int32_t
*
numOfOutput
,
int16_t
oType
,
int16_t
oBytes
)
{
int64_t
*
ptsList
,
int64_t
key
,
char
*
pOutput
,
char
*
ptsOutput
,
int32_t
*
numOfOutput
,
int16_t
oType
,
int16_t
oBytes
)
{
ScriptCtx
*
pCtx
=
pInit
;
ScriptCtx
*
pCtx
=
pInit
;
char
funcName
[
MAX_FUNC_NAME
]
=
{
0
};
char
funcName
[
MAX_FUNC_NAME
+
1
]
=
{
0
};
// one-more-space-for-null-terminator
sprintf
(
funcName
,
"%s_add"
,
pCtx
->
funcName
);
int
n
=
snprintf
(
funcName
,
sizeof
(
funcName
),
"%s_add"
,
pCtx
->
funcName
);
if
(
n
<
0
||
(
size_t
)
n
>=
sizeof
(
funcName
))
{
// FIXME: since prototype of this function does NOT return anything
assert
(
0
);
// TODO: assert has no effect in case when compiling with NDEBUG set
}
lua_State
*
lua
=
pCtx
->
pEnv
->
lua_state
;
lua_State
*
lua
=
pCtx
->
pEnv
->
lua_state
;
lua_getglobal
(
lua
,
funcName
);
lua_getglobal
(
lua
,
funcName
);
...
@@ -142,8 +150,12 @@ void taosLoadScriptNormal(void *pInit, char *pInput, int16_t iType, int16_t iByt
...
@@ -142,8 +150,12 @@ void taosLoadScriptNormal(void *pInit, char *pInput, int16_t iType, int16_t iByt
void
taosLoadScriptMerge
(
void
*
pInit
,
char
*
data
,
int32_t
numOfRows
,
char
*
pOutput
,
int32_t
*
numOfOutput
)
{
void
taosLoadScriptMerge
(
void
*
pInit
,
char
*
data
,
int32_t
numOfRows
,
char
*
pOutput
,
int32_t
*
numOfOutput
)
{
ScriptCtx
*
pCtx
=
pInit
;
ScriptCtx
*
pCtx
=
pInit
;
char
funcName
[
MAX_FUNC_NAME
]
=
{
0
};
char
funcName
[
MAX_FUNC_NAME
+
1
]
=
{
0
};
// one-more-space-for-null-terminator
sprintf
(
funcName
,
"%s_merge"
,
pCtx
->
funcName
);
int
n
=
snprintf
(
funcName
,
sizeof
(
funcName
),
"%s_merge"
,
pCtx
->
funcName
);
if
(
n
<
0
||
(
size_t
)
n
>=
sizeof
(
funcName
))
{
// FIXME: since prototype of this function does NOT return anything
assert
(
0
);
// TODO: assert has no effect in case when compiling with NDEBUG set
}
lua_State
*
lua
=
pCtx
->
pEnv
->
lua_state
;
lua_State
*
lua
=
pCtx
->
pEnv
->
lua_state
;
lua_getglobal
(
lua
,
funcName
);
lua_getglobal
(
lua
,
funcName
);
...
@@ -166,8 +178,12 @@ void taosLoadScriptMerge(void *pInit, char* data, int32_t numOfRows, char* pOutp
...
@@ -166,8 +178,12 @@ void taosLoadScriptMerge(void *pInit, char* data, int32_t numOfRows, char* pOutp
//do not support agg now
//do not support agg now
void
taosLoadScriptFinalize
(
void
*
pInit
,
int64_t
key
,
char
*
pOutput
,
int32_t
*
numOfOutput
)
{
void
taosLoadScriptFinalize
(
void
*
pInit
,
int64_t
key
,
char
*
pOutput
,
int32_t
*
numOfOutput
)
{
ScriptCtx
*
pCtx
=
pInit
;
ScriptCtx
*
pCtx
=
pInit
;
char
funcName
[
MAX_FUNC_NAME
]
=
{
0
};
char
funcName
[
MAX_FUNC_NAME
+
1
]
=
{
0
};
// one-more-space-for-null-terminator
sprintf
(
funcName
,
"%s_finalize"
,
pCtx
->
funcName
);
int
n
=
snprintf
(
funcName
,
sizeof
(
funcName
),
"%s_finalize"
,
pCtx
->
funcName
);
if
(
n
<
0
||
(
size_t
)
n
>=
sizeof
(
funcName
))
{
// FIXME: since prototype of this function does NOT return anything
assert
(
0
);
// TODO: assert has no effect in case when compiling with NDEBUG set
}
lua_State
*
lua
=
pCtx
->
pEnv
->
lua_state
;
lua_State
*
lua
=
pCtx
->
pEnv
->
lua_state
;
lua_getglobal
(
lua
,
funcName
);
lua_getglobal
(
lua
,
funcName
);
...
@@ -401,19 +417,23 @@ void addScriptEnvToPool(ScriptEnv *pEnv) {
...
@@ -401,19 +417,23 @@ void addScriptEnvToPool(ScriptEnv *pEnv) {
bool
hasBaseFuncDefinedInScript
(
lua_State
*
lua
,
const
char
*
funcPrefix
,
int32_t
len
)
{
bool
hasBaseFuncDefinedInScript
(
lua_State
*
lua
,
const
char
*
funcPrefix
,
int32_t
len
)
{
bool
ret
=
true
;
bool
ret
=
true
;
char
funcName
[
MAX_FUNC_NAME
];
char
funcName
[
MAX_FUNC_NAME
+
1
]
=
{
0
};
// one-more-space-for-null-terminator
memcpy
(
funcName
,
funcPrefix
,
len
);
const
char
*
base
[]
=
{
"_init"
,
"_add"
};
const
char
*
base
[]
=
{
"_init"
,
"_add"
};
for
(
int
i
=
0
;
(
i
<
sizeof
(
base
)
/
sizeof
(
base
[
0
]))
&&
(
ret
==
true
);
i
++
)
{
for
(
int
i
=
0
;
(
i
<
sizeof
(
base
)
/
sizeof
(
base
[
0
]))
&&
(
ret
==
true
);
i
++
)
{
memcpy
(
funcName
+
len
,
base
[
i
],
strlen
(
base
[
i
]));
int
n
=
snprintf
(
funcName
,
sizeof
(
funcName
),
"%.*s%s"
,
len
,
funcPrefix
,
base
[
i
]);
memset
(
funcName
+
len
+
strlen
(
base
[
i
]),
0
,
MAX_FUNC_NAME
-
len
-
strlen
(
base
[
i
]));
if
(
n
<
0
||
(
size_t
)
n
>=
sizeof
(
funcName
))
{
// FIXME: what internal error-code to set?
return
false
;
}
lua_getglobal
(
lua
,
funcName
);
lua_getglobal
(
lua
,
funcName
);
ret
=
lua_isfunction
(
lua
,
-
1
);
// exsit function or not
ret
=
lua_isfunction
(
lua
,
-
1
);
// exsit function or not
lua_pop
(
lua
,
1
);
lua_pop
(
lua
,
1
);
if
(
!
ret
)
// if it's not lua-function
break
;
}
}
return
ret
;
return
ret
;
}
}
bool
isValidScript
(
char
*
script
,
int32_t
len
)
{
bool
isValidScript
(
char
*
script
,
int32_t
len
)
{
ScriptEnv
*
pEnv
=
getScriptEnvFromPool
();
//
ScriptEnv
*
pEnv
=
getScriptEnvFromPool
();
//
...
@@ -432,7 +452,7 @@ bool isValidScript(char *script, int32_t len) {
...
@@ -432,7 +452,7 @@ bool isValidScript(char *script, int32_t len) {
}
}
lua_getglobal
(
lua
,
USER_FUNC_NAME
);
lua_getglobal
(
lua
,
USER_FUNC_NAME
);
const
char
*
name
=
lua_tostring
(
lua
,
-
1
);
const
char
*
name
=
lua_tostring
(
lua
,
-
1
);
if
(
name
==
NULL
||
strlen
(
name
)
>
=
USER_FUNC_NAME_LIMIT
)
{
if
(
name
==
NULL
||
strlen
(
name
)
>
USER_FUNC_NAME_LIMIT
)
{
lua_pop
(
lua
,
1
);
lua_pop
(
lua
,
1
);
addScriptEnvToPool
(
pEnv
);
addScriptEnvToPool
(
pEnv
);
qError
(
"error at %s name: %s, len = %d"
,
script
,
name
,
(
int
)(
strlen
(
name
)));
qError
(
"error at %s name: %s, len = %d"
,
script
,
name
,
(
int
)(
strlen
(
name
)));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录