提交 101a55d1 编写于 作者: C chenwei

fix: codex

1,VFS代码中不修改参数增加const修饰
2,fs_file_mapping.c: 增加安全函数的判空
3,path_cache.c: sizeof改为使用类型
4,fs_syscall.c: 对NULL解引用
5,VnodeLookup:冗余的判空,及不正确的判空

close: I3UMWD
Signed-off-by: Yansira's avataryansira <yansira@hotmail.com>
上级 c39c10c9
......@@ -1836,7 +1836,7 @@ ERROR_OUT:
return -fatfs_2_vfs(result);
}
int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, char *name)
int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, const char *name)
{
FATFS *fs = (FATFS *)vp->originMount->data;
DIR_FILE *dfp = (DIR_FILE *)vp->data;
......@@ -1898,7 +1898,7 @@ int fatfs_reclaim(struct Vnode *vp)
return 0;
}
int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, char *name)
int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, const char *name)
{
FATFS *fs = (FATFS *)vp->originMount->data;
DIR_FILE *dfp = (DIR_FILE *)vp->data;
......
......@@ -131,8 +131,8 @@ int fatfs_closedir(struct Vnode *vnode, struct fs_dirent_s *dir);
int fatfs_rename(struct Vnode *oldvnode, struct Vnode *newparent, const char *oldname, const char *newname);
int fatfs_mkfs (struct Vnode *device, int sectors, int option);
int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp);
int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, char *name);
int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, char *name);
int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, const char *name);
int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, const char *name);
int fatfs_ioctl(struct file *filep, int req, unsigned long arg);
int fatfs_fscheck(struct Vnode* vnode, struct fs_dirent_s *dir);
......
......@@ -85,8 +85,8 @@ struct VnodeOps {
int (*Open)(struct Vnode *vnode, int fd, int mode, int flags);
int (*Close)(struct Vnode *vnode);
int (*Reclaim)(struct Vnode *vnode);
int (*Unlink)(struct Vnode *parent, struct Vnode *vnode, char *fileName);
int (*Rmdir)(struct Vnode *parent, struct Vnode *vnode, char *dirName);
int (*Unlink)(struct Vnode *parent, struct Vnode *vnode, const char *fileName);
int (*Rmdir)(struct Vnode *parent, struct Vnode *vnode, const char *dirName);
int (*Mkdir)(struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode);
int (*Readdir)(struct Vnode *vnode, struct fs_dirent_s *dir);
int (*Opendir)(struct Vnode *vnode, struct fs_dirent_s *dir);
......
......@@ -603,7 +603,7 @@ int VfsJffs2Chattr(struct Vnode *pVnode, struct IATTR *attr)
return ret;
}
int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, char *path)
int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, const char *path)
{
int ret;
......@@ -620,7 +620,7 @@ int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, char *pa
return ret;
}
int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, char *path)
int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, const char *path)
{
int ret;
......
......@@ -270,11 +270,27 @@ int update_file_path(const char *old_path, const char *new_path)
continue;
}
int len = strlen(new_path) + 1;
filp->f_path = zalloc(len);
strncpy_s(filp->f_path, strlen(new_path) + 1, new_path, len);
char *tmp_path = LOS_MemAlloc(m_aucSysMem0, len);
if (tmp_path == NULL) {
PRINT_ERR("%s-%d: Mem alloc failed, path length(%d)\n", __FUNCTION__, __LINE__, len);
ret = VFS_ERROR;
goto out;
}
ret = strncpy_s(tmp_path, strlen(new_path) + 1, new_path, len);
if (ret != 0) {
(VOID)LOS_MemFree(m_aucSysMem0, tmp_path);
PRINT_ERR("%s-%d: strcpy failed.\n", __FUNCTION__, __LINE__);
ret = VFS_ERROR;
goto out;
}
free(filp->f_path);
filp->f_path = tmp_path;
}
ret = LOS_OK;
out:
(VOID)LOS_MuxUnlock(&g_file_mapping.lock);
(void)sem_post(&f_list->fl_sem);
return LOS_OK;
return ret;
}
#endif
......@@ -82,7 +82,7 @@ static uint32_t NameHash(const char *name, int len, struct Vnode *dvp)
{
uint32_t hash;
hash = fnv_32_buf(name, len, FNV1_32_INIT);
hash = fnv_32_buf(&dvp, sizeof(dvp), hash);
hash = fnv_32_buf(&dvp, sizeof(struct Vnode *), hash);
return hash;
}
......
......@@ -245,9 +245,6 @@ int VnodeDrop()
static char *NextName(char *pos, uint8_t *len)
{
char *name = NULL;
if (*pos == '\0') {
return NULL;
}
while (*pos != 0 && *pos == '/') {
pos++;
}
......@@ -319,6 +316,7 @@ static int Step(char **currentDir, struct Vnode **currentVnode, uint32_t flags)
}
nextDir = NextName(*currentDir, &len);
if (nextDir == NULL) {
// there is '/' at the end of the *currentDir.
*currentDir = NULL;
return LOS_OK;
}
......@@ -361,7 +359,6 @@ int VnodeLookup(const char *path, struct Vnode **result, uint32_t flags)
struct Vnode *startVnode = NULL;
char *normalizedPath = NULL;
int ret = PreProcess(path, &startVnode, &normalizedPath);
if (ret != LOS_OK) {
PRINT_ERR("[VFS]lookup failed, invalid path=%s err = %d\n", path, ret);
......@@ -377,9 +374,9 @@ int VnodeLookup(const char *path, struct Vnode **result, uint32_t flags)
char *currentDir = normalizedPath;
struct Vnode *currentVnode = startVnode;
while (currentDir && *currentDir != '\0') {
while (*currentDir != '\0') {
ret = Step(&currentDir, &currentVnode, flags);
if (*currentDir == '\0') {
if (currentDir == NULL || *currentDir == '\0') {
// return target or parent vnode as result
*result = currentVnode;
} else if (VfsVnodePermissionCheck(currentVnode, EXEC_OP)) {
......
......@@ -270,13 +270,11 @@ int SysOpen(const char *path, int oflags, ...)
mode_t mode = DEFAULT_FILE_MODE; /* 0666: File read-write properties. */
char *pathRet = NULL;
if (path == NULL && *path == 0) {
return -EINVAL;
}
ret = UserPathCopy(path, &pathRet);
if (ret != 0) {
return ret;
if (path != NULL) {
ret = UserPathCopy(path, &pathRet);
if (ret != 0) {
goto ERROUT_PATH_FREE;
}
}
procFd = AllocProcessFd();
......@@ -310,15 +308,16 @@ int SysOpen(const char *path, int oflags, ...)
return procFd;
ERROUT:
if (pathRet != NULL) {
LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
if (ret >= 0) {
AssociateSystemFd(procFd, ret);
ret = procFd;
} else {
FreeProcessFd(procFd);
}
ERROUT_PATH_FREE:
if (pathRet != NULL) {
LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册