Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
6f264b5d
T
Third Party CJSON
项目概览
OpenHarmony
/
Third Party CJSON
大约 1 年 前同步成功
通知
6
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party CJSON
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6f264b5d
编写于
3月 02, 2018
作者:
M
Max Bruckner
提交者:
GitHub
3月 02, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #249 from DaveGamble/fix-add-item
Release 1.7.4
上级
a559eac4
5da9edc8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
47 addition
and
16 deletion
+47
-16
CHANGELOG.md
CHANGELOG.md
+7
-1
CMakeLists.txt
CMakeLists.txt
+1
-1
Makefile
Makefile
+1
-1
cJSON.c
cJSON.c
+17
-12
cJSON.h
cJSON.h
+1
-1
tests/misc_tests.c
tests/misc_tests.c
+20
-0
未找到文件。
CHANGELOG.md
浏览文件 @
6f264b5d
1.7.2
1.7.4
=====
Fixes:
------
*
Fix potential use after free if the
`string`
parameter to
`cJSON_AddItemToObject`
is an alias of the
`string`
property of the object that is added (#248). Thanks @hhallen for reporting.
1.
7.3
=====
=====
Fixes:
Fixes:
------
------
...
...
CMakeLists.txt
浏览文件 @
6f264b5d
...
@@ -7,7 +7,7 @@ include(GNUInstallDirs)
...
@@ -7,7 +7,7 @@ include(GNUInstallDirs)
set
(
PROJECT_VERSION_MAJOR 1
)
set
(
PROJECT_VERSION_MAJOR 1
)
set
(
PROJECT_VERSION_MINOR 7
)
set
(
PROJECT_VERSION_MINOR 7
)
set
(
PROJECT_VERSION_PATCH
3
)
set
(
PROJECT_VERSION_PATCH
4
)
set
(
CJSON_VERSION_SO 1
)
set
(
CJSON_VERSION_SO 1
)
set
(
CJSON_UTILS_VERSION_SO 1
)
set
(
CJSON_UTILS_VERSION_SO 1
)
set
(
PROJECT_VERSION
"
${
PROJECT_VERSION_MAJOR
}
.
${
PROJECT_VERSION_MINOR
}
.
${
PROJECT_VERSION_PATCH
}
"
)
set
(
PROJECT_VERSION
"
${
PROJECT_VERSION_MAJOR
}
.
${
PROJECT_VERSION_MINOR
}
.
${
PROJECT_VERSION_PATCH
}
"
)
...
...
Makefile
浏览文件 @
6f264b5d
...
@@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
...
@@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
LDLIBS
=
-lm
LDLIBS
=
-lm
LIBVERSION
=
1.7.
3
LIBVERSION
=
1.7.
4
CJSON_SOVERSION
=
1
CJSON_SOVERSION
=
1
UTILS_SOVERSION
=
1
UTILS_SOVERSION
=
1
...
...
cJSON.c
浏览文件 @
6f264b5d
...
@@ -82,7 +82,7 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) {
...
@@ -82,7 +82,7 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) {
}
}
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH !=
3
)
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH !=
4
)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
#endif
#endif
...
@@ -1895,33 +1895,38 @@ static void* cast_away_const(const void* string)
...
@@ -1895,33 +1895,38 @@ static void* cast_away_const(const void* string)
static
cJSON_bool
add_item_to_object
(
cJSON
*
const
object
,
const
char
*
const
string
,
cJSON
*
const
item
,
const
internal_hooks
*
const
hooks
,
const
cJSON_bool
constant_key
)
static
cJSON_bool
add_item_to_object
(
cJSON
*
const
object
,
const
char
*
const
string
,
cJSON
*
const
item
,
const
internal_hooks
*
const
hooks
,
const
cJSON_bool
constant_key
)
{
{
char
*
new_key
=
NULL
;
int
new_type
=
cJSON_Invalid
;
if
((
object
==
NULL
)
||
(
string
==
NULL
)
||
(
item
==
NULL
))
if
((
object
==
NULL
)
||
(
string
==
NULL
)
||
(
item
==
NULL
))
{
{
return
false
;
return
false
;
}
}
if
(
!
(
item
->
type
&
cJSON_StringIsConst
)
&&
(
item
->
string
!=
NULL
))
{
hooks
->
deallocate
(
item
->
string
);
}
if
(
constant_key
)
if
(
constant_key
)
{
{
item
->
string
=
(
char
*
)
cast_away_const
(
string
);
new_key
=
(
char
*
)
cast_away_const
(
string
);
item
->
type
|=
cJSON_StringIsConst
;
new_type
=
item
->
type
|
cJSON_StringIsConst
;
}
}
else
else
{
{
char
*
key
=
(
char
*
)
cJSON_strdup
((
const
unsigned
char
*
)
string
,
hooks
);
new_
key
=
(
char
*
)
cJSON_strdup
((
const
unsigned
char
*
)
string
,
hooks
);
if
(
key
==
NULL
)
if
(
new_
key
==
NULL
)
{
{
return
false
;
return
false
;
}
}
item
->
string
=
key
;
new_type
=
item
->
type
&
~
cJSON_StringIsConst
;
item
->
type
&=
~
cJSON_StringIsConst
;
}
}
if
(
!
(
item
->
type
&
cJSON_StringIsConst
)
&&
(
item
->
string
!=
NULL
))
{
hooks
->
deallocate
(
item
->
string
);
}
item
->
string
=
new_key
;
item
->
type
=
new_type
;
return
add_item_to_array
(
object
,
item
);
return
add_item_to_array
(
object
,
item
);
}
}
...
...
cJSON.h
浏览文件 @
6f264b5d
...
@@ -31,7 +31,7 @@ extern "C"
...
@@ -31,7 +31,7 @@ extern "C"
/* project version */
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH
3
#define CJSON_VERSION_PATCH
4
#include <stddef.h>
#include <stddef.h>
...
...
tests/misc_tests.c
浏览文件 @
6f264b5d
...
@@ -508,6 +508,25 @@ static void cjson_create_array_reference_should_create_an_array_reference(void)
...
@@ -508,6 +508,25 @@ static void cjson_create_array_reference_should_create_an_array_reference(void)
cJSON_Delete
(
number_reference
);
cJSON_Delete
(
number_reference
);
}
}
static
void
cjson_add_item_to_object_should_not_use_after_free_when_string_is_aliased
(
void
)
{
cJSON
*
object
=
cJSON_CreateObject
();
cJSON
*
number
=
cJSON_CreateNumber
(
42
);
char
*
name
=
(
char
*
)
cJSON_strdup
((
const
unsigned
char
*
)
"number"
,
&
global_hooks
);
TEST_ASSERT_NOT_NULL
(
object
);
TEST_ASSERT_NOT_NULL
(
number
);
TEST_ASSERT_NOT_NULL
(
name
);
number
->
string
=
name
;
/* The following should not have a use after free
* that would show up in valgrind or with AddressSanitizer */
cJSON_AddItemToObject
(
object
,
number
->
string
,
number
);
cJSON_Delete
(
object
);
}
int
main
(
void
)
int
main
(
void
)
{
{
UNITY_BEGIN
();
UNITY_BEGIN
();
...
@@ -530,6 +549,7 @@ int main(void)
...
@@ -530,6 +549,7 @@ int main(void)
RUN_TEST
(
cjson_create_string_reference_should_create_a_string_reference
);
RUN_TEST
(
cjson_create_string_reference_should_create_a_string_reference
);
RUN_TEST
(
cjson_create_object_reference_should_create_an_object_reference
);
RUN_TEST
(
cjson_create_object_reference_should_create_an_object_reference
);
RUN_TEST
(
cjson_create_array_reference_should_create_an_array_reference
);
RUN_TEST
(
cjson_create_array_reference_should_create_an_array_reference
);
RUN_TEST
(
cjson_add_item_to_object_should_not_use_after_free_when_string_is_aliased
);
return
UNITY_END
();
return
UNITY_END
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录