代码Review issue模板
【Code Review】There is a logic error in the remove_name function of the rootfs_store.c file
iSulad version/branch
the latest version, implement_image
Code Segment
static int remove_name(cntrootfs_t *cntr, const char *name)
{
...
for (i = 0; i < cntr->srootfs->names_len; i++) {
if (strcmp(cntr->srootfs->names[i], name) == 0) {
count++;
}
}
new_size = (cntr->srootfs->names_len - count) * sizeof(char *);
tmp_names = (char **)util_common_calloc_s(new_size);
if (tmp_names == NULL) {
ERROR("Out of memory");
return -1;
}
...
}
Problem Analysis
When the name of the container is unique and the same as the name of the input parameter, the program will exit abnormally and there is a memory leak.
Workaround
When the name of the container is unique and the same as the name of the input parameter, the memory should be released directly, and the length is set to 0
static int remove_name(cntrootfs_t *cntr, const char *name)
{
...
for (i = 0; i < cntr->srootfs->names_len; i++) {
if (strcmp(cntr->srootfs->names[i], name) == 0) {
count++;
}
}
if (cntr->srootfs->names_len == count) {
util_free_array_by_len(cntr->srootfs->names, cntr->srootfs->names_len);
cntr->srootfs->names = NULL;
cntr->srootfs->names_len = 0;
return 0;
}
new_size = (cntr->srootfs->names_len - count) * sizeof(char *);
tmp_names = (char **)util_common_calloc_s(new_size);
if (tmp_names == NULL) {
ERROR("Out of memory");
return -1;
}
...
}
【代码检视】rootfs_store.c文件的remove_name函数存在逻辑错误
iSulad 版本及分支
the latest version, implement_image
代码片段
static int remove_name(cntrootfs_t *cntr, const char *name)
{
...
for (i = 0; i < cntr->srootfs->names_len; i++) {
if (strcmp(cntr->srootfs->names[i], name) == 0) {
count++;
}
}
new_size = (cntr->srootfs->names_len - count) * sizeof(char *);
tmp_names = (char **)util_common_calloc_s(new_size);
if (tmp_names == NULL) {
ERROR("Out of memory");
return -1;
}
...
}
问题分析
当容器的names唯一且与入参name相同时,程序会异常退出且有内存泄漏。
解决方法
当容器的names唯一且与入参name相同时,应该直接释放内存,且把长度设置成0
static int remove_name(cntrootfs_t *cntr, const char *name)
{
...
for (i = 0; i < cntr->srootfs->names_len; i++) {
if (strcmp(cntr->srootfs->names[i], name) == 0) {
count++;
}
}
if (cntr->srootfs->names_len == count) {
util_free_array_by_len(cntr->srootfs->names, cntr->srootfs->names_len);
cntr->srootfs->names = NULL;
cntr->srootfs->names_len = 0;
return 0;
}
new_size = (cntr->srootfs->names_len - count) * sizeof(char *);
tmp_names = (char **)util_common_calloc_s(new_size);
if (tmp_names == NULL) {
ERROR("Out of memory");
return -1;
}
...
}
功能测试 issue模板
【Function Test】Segmentation fault from isula inspect
What version of iSulad and which branch are you using?
Client:
Version: 2.0.2
Git commit: 259d4126b9cfbf1ffce64ba3d65cc2de98298f76
Built: 2020-06-22T15:30:09.183997400+08:00
Server:
Version: 2.0.2
Git commit: 259d4126b9cfbf1ffce64ba3d65cc2de98298f76
Built: 2020-06-22T15:30:09.183997400+08:00
master && stable-2.0 && implement_image
What operating system (Linux, Windows,...) and version? What compiler are you using ?
Linux, fedora 32, gcc version 10.1.1
What did you do and what did you see ?
When executing command to inspect a empty object, a coredump occurs in the client program.
➜ iSulad git:(implement_image) ✗ isula inspect ""
Segmentation fault (core dumpd)
What did you expect to see?
The program does not cause coredump, and it prompts that the inspection failed. eg:
➜ iSulad git:(implement_image) ✗ isula inspect ""
[]
Inspect error: No such object:
What did you do and what did you see ?
When executing command to inspect a empty object, a coredump occurs in the client program.
【功能测试】isula inspect 段错误
iSula版本信息及项目分支
Client:
Version: 2.0.2
Git commit: 259d4126b9cfbf1ffce64ba3d65cc2de98298f76
Built: 2020-06-22T15:30:09.183997400+08:00
Server:
Version: 2.0.2
Git commit: 259d4126b9cfbf1ffce64ba3d65cc2de98298f76
Built: 2020-06-22T15:30:09.183997400+08:00
master && stable-2.0 && implement_image
操作系统版本及编译器版本
Linux, fedora 32, gcc version 10.1.1
问题是如何引起的?重现步骤是什么?问题现象是什么?
异常测试时,inspect空字符串会导致客户端程序coredump。
➜ iSulad git:(implement_image) ✗ isula inspect ""
Segmentation fault (core dumpd)
预期结果应该是什么?
程序不能出现coredump,且应该有清晰的错误提示. 例如:
➜ iSulad git:(implement_image) ✗ isula inspect ""
[]
Inspect error: No such object:
开发者测试 issue模板
c
【开发者测试】 升级场景加载本地已存在的v1镜像导致iSulad coredump
用例描述
测试套: StorageImagesCompatibilityUnitTest
用例名:test_load_v1_image
TEST_F(StorageImagesCompatibilityUnitTest, test_load_v1_image)
{
...
opts.driver_name = strdup("overlay");
ASSERT_EQ(image_store_init(&opts), 0); --- core dumpd
free(opts.storage_root);
...
}
环境:
操作系统/编译器
Linux, fedora 32, gcc version 10.1.1
iSulad版本
Client:
Version: 2.0.2
Git commit: 259d4126b9cfbf1ffce64ba3d65cc2de98298f76
Built: 2020-06-22T15:30:09.183997400+08:00Server:
Version: 2.0.2
Git commit: 259d4126b9cfbf1ffce64ba3d65cc2de98298f76
Built: 2020-06-22T15:30:09.183997400+08:00开发分支
implement_image
根因分析
从layer store获取的层信息存在多个层没有parent(正常情况下只有一个层没有)
解决办法
对外部模块获取的层信息进行严格校验
MR: https://gitee.com/openeuler/iSulad/commit/99a42f7d1c60a2140d6b3da3dd8d23196a68bca5
[DT/Function Test/Code Review]
What version of iSulad and which branch are you using?
What operating system (Linux, Windows,...) and version? What compiler are you using ?
What did you do and what did you see ?
What did you expect to see?
【开发者测试/功能测试/代码检视】
iSula版本信息及项目分支
操作系统版本及编译器版本
问题描述及重现步骤
预期结果
Pull Request Template
Description
Related Issue
Type of change
- Bug Fix
- New Feature
- Breaking Change
- Code Refactoring
- Interface Change
- Documentation Update
Test Case
Validation Report
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- Test A
- Test B
Test Configuration:
-
Firmware version:
-
Hardware:
-
Toolchain:
-
SDK:
描述
关联issue
修改类型
- 问题修复
- 新特性开发
- 代码重构
- 接口变更
- 文档更新