Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
d75563fb
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
大约 1 年 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d75563fb
编写于
10月 09, 2022
作者:
C
cheng_jinsong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
malloc/calloc分配内存后检验
Signed-off-by:
N
cheng_jinsong
<
chengjinsong2@huawei.com
>
上级
35c8fb3f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
0 deletion
+13
-0
services/begetctl/dump_service.c
services/begetctl/dump_service.c
+1
-0
test/unittest/init/service_unittest.cpp
test/unittest/init/service_unittest.cpp
+10
-0
test/unittest/param/param_unittest.cpp
test/unittest/param/param_unittest.cpp
+2
-0
未找到文件。
services/begetctl/dump_service.c
浏览文件 @
d75563fb
...
...
@@ -37,6 +37,7 @@ static int main_cmd(BShellHandle shell, int argc, char **argv)
}
size_t
serviceNameLen
=
strlen
(
argv
[
1
])
+
strlen
(
argv
[
2
])
+
2
;
// 2 is \0 and #
char
*
cmd
=
(
char
*
)
calloc
(
1
,
serviceNameLen
);
BEGET_ERROR_CHECK
(
cmd
!=
NULL
,
return
0
,
"failed to allocate cmd memory"
);
BEGET_ERROR_CHECK
(
sprintf_s
(
cmd
,
serviceNameLen
,
"%s#%s"
,
argv
[
1
],
argv
[
2
])
>=
0
,
free
(
cmd
);
return
0
,
"dump service arg create failed"
);
CmdClientInit
(
INIT_CONTROL_FD_SOCKET_PATH
,
ACTION_DUMP
,
cmd
);
...
...
test/unittest/init/service_unittest.cpp
浏览文件 @
d75563fb
...
...
@@ -82,15 +82,18 @@ HWTEST_F(ServiceUnitTest, case02, TestSize.Level1)
cJSON
*
serviceItem
=
cJSON_GetObjectItem
(
jobItem
,
"services"
);
ASSERT_NE
(
nullptr
,
serviceItem
);
Service
*
service
=
AddService
(
"test_service8"
);
ASSERT_NE
(
nullptr
,
service
);
int
ret
=
ParseOneService
(
serviceItem
,
service
);
EXPECT_EQ
(
ret
,
0
);
int
*
fds
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
1
);
// ServiceStop will release fds
ASSERT_NE
(
nullptr
,
fds
);
UpdaterServiceFds
(
service
,
fds
,
1
);
service
->
attribute
=
SERVICE_ATTR_ONDEMAND
;
ret
=
ServiceStart
(
service
);
EXPECT_EQ
(
ret
,
0
);
CmdLines
*
cmdline
=
(
CmdLines
*
)
malloc
(
sizeof
(
CmdLines
)
+
sizeof
(
CmdLine
));
ASSERT_NE
(
nullptr
,
cmdline
);
cmdline
->
cmdNum
=
1
;
cmdline
->
cmds
[
0
].
cmdIndex
=
0
;
service
->
restartArg
=
cmdline
;
...
...
@@ -213,20 +216,26 @@ HWTEST_F(ServiceUnitTest, TestServiceManagerRelease, TestSize.Level1)
service
=
AddService
(
"test_service5"
);
ASSERT_NE
(
nullptr
,
service
);
service
->
pathArgs
.
argv
=
(
char
**
)
malloc
(
sizeof
(
char
*
));
ASSERT_NE
(
nullptr
,
service
->
pathArgs
.
argv
);
service
->
pathArgs
.
count
=
1
;
const
char
*
path
=
"/data/init_ut/test_service_release"
;
service
->
pathArgs
.
argv
[
0
]
=
strdup
(
path
);
service
->
writePidArgs
.
argv
=
(
char
**
)
malloc
(
sizeof
(
char
*
));
ASSERT_NE
(
nullptr
,
service
->
writePidArgs
.
argv
);
service
->
writePidArgs
.
count
=
1
;
service
->
writePidArgs
.
argv
[
0
]
=
strdup
(
path
);
service
->
servPerm
.
caps
=
(
unsigned
int
*
)
malloc
(
sizeof
(
unsigned
int
));
ASSERT_NE
(
nullptr
,
service
->
servPerm
.
caps
);
service
->
servPerm
.
gIDArray
=
(
gid_t
*
)
malloc
(
sizeof
(
gid_t
));
ASSERT_NE
(
nullptr
,
service
->
servPerm
.
gIDArray
);
service
->
socketCfg
=
(
ServiceSocket
*
)
malloc
(
sizeof
(
ServiceSocket
));
ASSERT_NE
(
nullptr
,
service
->
socketCfg
);
service
->
socketCfg
->
sockFd
=
0
;
service
->
socketCfg
->
next
=
nullptr
;
service
->
fileCfg
=
(
ServiceFile
*
)
malloc
(
sizeof
(
ServiceFile
));
ASSERT_NE
(
nullptr
,
service
->
fileCfg
);
service
->
fileCfg
->
fd
=
0
;
service
->
fileCfg
->
next
=
nullptr
;
ReleaseService
(
service
);
...
...
@@ -330,6 +339,7 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1)
service
->
servPerm
.
gIDCnt
=
-
1
;
service
->
servPerm
.
uID
=
0
;
unsigned
int
*
caps
=
(
unsigned
int
*
)
calloc
(
1
,
sizeof
(
unsigned
int
)
*
1
);
ASSERT_NE
(
nullptr
,
caps
);
caps
[
0
]
=
FULL_CAP
;
service
->
servPerm
.
caps
=
caps
;
service
->
servPerm
.
capsCnt
=
1
;
...
...
test/unittest/param/param_unittest.cpp
浏览文件 @
d75563fb
...
...
@@ -405,7 +405,9 @@ HWTEST_F(ParamUnitTest, TestLinuxRWLock, TestSize.Level0)
ParamRWMutexDelete
(
nullptr
);
ParamMutexDelete
(
nullptr
);
WorkSpace
*
workspace1
=
(
WorkSpace
*
)
malloc
(
sizeof
(
WorkSpace
)
+
strlen
(
"testfilename1"
));
ASSERT_NE
(
nullptr
,
workspace1
);
WorkSpace
*
workspace2
=
(
WorkSpace
*
)
malloc
(
sizeof
(
WorkSpace
)
+
strlen
(
"testfilename1"
));
ASSERT_NE
(
nullptr
,
workspace2
);
if
(
strcpy_s
(
workspace1
->
fileName
,
strlen
(
"testfilename1"
),
"testfilename"
)
!=
EOK
)
{
EXPECT_EQ
(
0
,
1
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录