fix: codex clean

1. 修复可能对NULL指针解引用的场景
2. 将不修改内容的指针入参修改为const
3. 对getpgrp的返回值进行校验后再使用
4. 修复了局部变量未初始化的问题

Close #I3UOFN

Signed-off-by: Far <yesiyuan2@huawei.com>
This commit is contained in:
Far
2021-06-07 16:49:02 +08:00
parent 3f16f1684a
commit b5370af822
6 changed files with 27 additions and 12 deletions

View File

@@ -49,6 +49,7 @@
int main(int argc, char * const *argv)
{
int ret;
pid_t gid;
const char *shellPath = "/bin/mksh";
#ifdef LOSCFG_QUICK_START
@@ -74,9 +75,14 @@ int main(int argc, char * const *argv)
if (ret < 0) {
printf("Failed to fork for shell\n");
} else if (ret == 0) {
ret = tcsetpgrp(STDIN_FILENO, getpgrp());
gid = getpgrp();
if (gid < 0) {
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
exit(0);
}
ret = tcsetpgrp(STDIN_FILENO, gid);
if (ret != 0) {
printf("tcsetpgrp failed, pgrpid %d, errno %d\n", getpgrp(), errno);
printf("tcsetpgrp failed, errno %d\n", errno);
exit(0);
}
(void)execve(shellPath, NULL, NULL);