fix: add null check in rmdir/unlinkat

close: #I4ATUC

Signed-off-by: Leon Chan <chenwei26@huawei.com>
This commit is contained in:
Leon Chan
2021-09-18 15:02:55 +08:00
parent 792664a540
commit 23f1351aa3
2 changed files with 22 additions and 1 deletions
+6
View File
@@ -111,6 +111,12 @@ int do_rmdir(int dirfd, const char *pathname)
char *name = NULL;
int ret;
if (pathname == NULL)
{
ret = -EINVAL;
goto errout;
}
/* Get relative path by dirfd*/
ret = get_path_from_fd(dirfd, &relativepath);
if (ret < 0)
+16 -1
View File
@@ -190,12 +190,27 @@ extern int do_rmdir(int dirfd, const char *pathname);
int unlinkat(int dirfd, const char *pathname, int flag)
{
int ret;
if (pathname == NULL)
{
ret = -EINVAL;
goto errout;
}
/* Now flag only support 0 && AT_REMOVEDIR */
if ((flag & ~AT_REMOVEDIR) != 0)
return VFS_ERROR;
{
ret = -EINVAL;
goto errout;
}
if (flag & AT_REMOVEDIR)
return do_rmdir(dirfd, pathname);
return do_unlink(dirfd, pathname);
errout:
set_errno(-ret);
return VFS_ERROR;
}