Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
a313fe80
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a313fe80
编写于
5月 12, 2020
作者:
W
wujing
提交者:
lifeng68
7月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix memory out of bound errors
Signed-off-by:
N
wujing
<
wujing50@huawei.com
>
上级
fe91e7dd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
30 deletion
+27
-30
src/image/oci/storage/image_store/image_store.c
src/image/oci/storage/image_store/image_store.c
+27
-30
未找到文件。
src/image/oci/storage/image_store/image_store.c
浏览文件 @
a313fe80
...
...
@@ -1028,7 +1028,7 @@ char *image_store_lookup(const char *id)
return
image_id
;
}
static
c
onst
c
har
*
get_value_from_json_map_string_string
(
json_map_string_string
*
map
,
const
char
*
key
)
static
char
*
get_value_from_json_map_string_string
(
json_map_string_string
*
map
,
const
char
*
key
)
{
size_t
i
;
...
...
@@ -1037,7 +1037,7 @@ static const char *get_value_from_json_map_string_string(json_map_string_string
}
for
(
i
=
0
;
i
<
map
->
len
;
i
++
)
{
if
(
strcmp
(
key
,
map
->
keys
[
i
])
==
0
)
{
return
map
->
values
[
i
]
;
return
util_strdup_s
(
map
->
values
[
i
])
;
}
}
...
...
@@ -1099,7 +1099,7 @@ static int remove_image_from_memory(const char *id)
image_t
*
img
=
NULL
;
size_t
i
=
0
;
int
ret
=
0
;
c
onst
c
har
*
digest
=
NULL
;
char
*
digest
=
NULL
;
img
=
lookup
(
id
);
if
(
img
==
NULL
)
{
...
...
@@ -1149,6 +1149,7 @@ static int remove_image_from_memory(const char *id)
}
out:
free
(
digest
);
image_ref_dec
(
img
);
return
ret
;
}
...
...
@@ -1452,60 +1453,59 @@ static int update_image_with_big_data(image_t *img, const char *key, const char
int
ret
=
0
;
bool
size_found
=
false
;
int64_t
old_size
;
c
onst
c
har
*
old_digest
=
NULL
;
char
*
old_digest
=
NULL
;
char
*
new_digest
=
NULL
;
char
*
full_digest
=
NULL
;
bool
add_name
=
true
;
size_t
i
;
digest_image_t
*
digest_filter_images
=
NULL
;
storage_image
*
im
=
NULL
;
im
=
img
->
simage
;
if
(
im
->
big_data_sizes
==
NULL
)
{
im
->
big_data_sizes
=
(
json_map_string_int64
*
)
util_common_calloc_s
(
sizeof
(
json_map_string_int64
));
if
(
im
->
big_data_sizes
==
NULL
)
{
if
(
img
->
simage
->
big_data_sizes
==
NULL
)
{
img
->
simage
->
big_data_sizes
=
(
json_map_string_int64
*
)
util_common_calloc_s
(
sizeof
(
json_map_string_int64
));
if
(
img
->
simage
->
big_data_sizes
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
}
}
size_found
=
get_value_from_json_map_string_int64
(
im
->
big_data_sizes
,
key
,
&
old_size
);
size_found
=
get_value_from_json_map_string_int64
(
im
g
->
simage
->
big_data_sizes
,
key
,
&
old_size
);
if
(
size_found
)
{
update_json_map_string_int64
(
im
->
big_data_sizes
,
key
,
(
int64_t
)
strlen
(
data
));
update_json_map_string_int64
(
im
g
->
simage
->
big_data_sizes
,
key
,
(
int64_t
)
strlen
(
data
));
}
else
{
append_json_map_string_int64
(
im
->
big_data_sizes
,
key
,
(
int64_t
)
strlen
(
data
));
append_json_map_string_int64
(
im
g
->
simage
->
big_data_sizes
,
key
,
(
int64_t
)
strlen
(
data
));
}
if
(
im
->
big_data_digests
==
NULL
)
{
im
->
big_data_digests
=
(
json_map_string_string
*
)
util_common_calloc_s
(
sizeof
(
json_map_string_string
));
if
(
im
->
big_data_digests
==
NULL
)
{
if
(
im
g
->
simage
->
big_data_digests
==
NULL
)
{
im
g
->
simage
->
big_data_digests
=
(
json_map_string_string
*
)
util_common_calloc_s
(
sizeof
(
json_map_string_string
));
if
(
im
g
->
simage
->
big_data_digests
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
}
}
old_digest
=
get_value_from_json_map_string_string
(
im
->
big_data_digests
,
key
);
old_digest
=
get_value_from_json_map_string_string
(
im
g
->
simage
->
big_data_digests
,
key
);
new_digest
=
sha256_digest_str
(
data
);
full_digest
=
util_full_digest
(
new_digest
);
if
(
old_digest
!=
NULL
)
{
update_json_map_string_string
(
im
->
big_data_digests
,
key
,
full_digest
);
update_json_map_string_string
(
im
g
->
simage
->
big_data_digests
,
key
,
full_digest
);
}
else
{
append_json_map_string_string
(
im
->
big_data_digests
,
key
,
full_digest
);
append_json_map_string_string
(
im
g
->
simage
->
big_data_digests
,
key
,
full_digest
);
}
if
(
!
size_found
||
old_size
!=
(
int64_t
)
strlen
(
data
)
||
old_digest
==
NULL
||
strcmp
(
old_digest
,
new_digest
)
!=
0
)
{
if
(
!
size_found
||
old_size
!=
(
int64_t
)
strlen
(
data
)
||
old_digest
==
NULL
||
strcmp
(
old_digest
,
full_digest
)
!=
0
)
{
*
should_save
=
true
;
}
for
(
i
=
0
;
i
<
im
->
big_data_names_len
;
i
++
)
{
if
(
strcmp
(
im
->
big_data_names
[
i
],
key
)
==
0
)
{
for
(
i
=
0
;
i
<
im
g
->
simage
->
big_data_names_len
;
i
++
)
{
if
(
strcmp
(
im
g
->
simage
->
big_data_names
[
i
],
key
)
==
0
)
{
add_name
=
false
;
break
;
}
}
if
(
add_name
)
{
if
(
append_big_data_name
(
im
,
key
)
!=
0
)
{
if
(
append_big_data_name
(
im
g
->
simage
,
key
)
!=
0
)
{
ERROR
(
"Failed to append big data name"
);
ret
=
-
1
;
goto
out
;
...
...
@@ -1514,7 +1514,7 @@ static int update_image_with_big_data(image_t *img, const char *key, const char
}
if
(
strcmp
(
key
,
IMAGE_DIGEST_BIG_DATA_KEY
)
==
0
)
{
if
(
old_digest
!=
NULL
&&
strcmp
(
old_digest
,
new_digest
)
!=
0
&&
strcmp
(
old_digest
,
im
->
digest
)
!=
0
)
{
if
(
old_digest
!=
NULL
&&
strcmp
(
old_digest
,
full_digest
)
!=
0
&&
strcmp
(
old_digest
,
img
->
simage
->
digest
)
!=
0
)
{
if
(
remove_image_from_digest_index
(
img
,
old_digest
)
!=
0
)
{
ERROR
(
"Failed to remove the image from the list of images in the digest-based "
"index which corresponds to the old digest for this item, unless it's also the hard-coded digest"
);
...
...
@@ -1525,7 +1525,7 @@ static int update_image_with_big_data(image_t *img, const char *key, const char
// add the image to the list of images in the digest-based index which
// corresponds to the new digest for this item, unless it's already there
digest_filter_images
=
(
digest_image_t
*
)
map_search
(
g_image_store
->
bydigest
,
(
void
*
)
new
_digest
);
digest_filter_images
=
(
digest_image_t
*
)
map_search
(
g_image_store
->
bydigest
,
(
void
*
)
full
_digest
);
if
(
digest_filter_images
!=
NULL
)
{
digest_image_slice_without_value
(
digest_filter_images
,
img
);
if
(
append_image_to_digest_images
(
digest_filter_images
,
img
)
!=
0
)
{
...
...
@@ -1537,6 +1537,7 @@ static int update_image_with_big_data(image_t *img, const char *key, const char
}
out:
free
(
old_digest
);
free
(
new_digest
);
free
(
full_digest
);
return
ret
;
...
...
@@ -2049,7 +2050,6 @@ static char *get_digest_with_update_big_data(const char *id, const char *key)
{
image_t
*
img
=
NULL
;
char
*
data
=
NULL
;
const
char
*
value
=
NULL
;
char
*
digest
=
NULL
;
data
=
image_store_big_data
(
id
,
key
);
...
...
@@ -2072,8 +2072,7 @@ static char *get_digest_with_update_big_data(const char *id, const char *key)
return
NULL
;
}
value
=
get_value_from_json_map_string_string
(
img
->
simage
->
big_data_digests
,
key
);
digest
=
util_strdup_s
(
value
);
digest
=
get_value_from_json_map_string_string
(
img
->
simage
->
big_data_digests
,
key
);
image_ref_dec
(
img
);
...
...
@@ -2083,7 +2082,6 @@ static char *get_digest_with_update_big_data(const char *id, const char *key)
char
*
image_store_big_data_digest
(
const
char
*
id
,
const
char
*
key
)
{
image_t
*
img
=
NULL
;
const
char
*
value
=
NULL
;
char
*
digest
=
NULL
;
if
(
key
==
NULL
||
strlen
(
key
)
==
0
)
{
...
...
@@ -2102,8 +2100,7 @@ char *image_store_big_data_digest(const char *id, const char *key)
return
NULL
;
}
value
=
get_value_from_json_map_string_string
(
img
->
simage
->
big_data_digests
,
key
);
digest
=
util_strdup_s
(
value
);
digest
=
get_value_from_json_map_string_string
(
img
->
simage
->
big_data_digests
,
key
);
image_ref_dec
(
img
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录