diff --git a/fs/fat/os_adapt/fatfs.c b/fs/fat/os_adapt/fatfs.c index d62a15c62ae12cf4cad9b667a0c266e7442e5e88..933b169f008202043f3a2efab3e66c05d62b4645 100755 --- a/fs/fat/os_adapt/fatfs.c +++ b/fs/fat/os_adapt/fatfs.c @@ -1371,7 +1371,7 @@ int fatfs_readdir(struct Vnode *vp, struct fs_dirent_s *idir) } DEF_NAMBUF; INIT_NAMBUF(fs); - for (i = 0; i < DIR_READ_COUNT && i < idir->read_cnt; i++) { + for (i = 0; i < idir->read_cnt; i++) { result = dir_read(dp, 0); if (result == FR_NO_FILE) { break; diff --git a/fs/include/fs/fs_operation.h b/fs/include/fs/fs_operation.h index 23898d8896d5cee91bb1dfd359f7e99ab42e9190..ab9287bf774588edfc85a740e0e39ca1c287be79 100644 --- a/fs/include/fs/fs_operation.h +++ b/fs/include/fs/fs_operation.h @@ -113,7 +113,7 @@ extern void dec_mapping_nolock(struct page_mapping *mapping); * ****************************************************************************/ -extern int update_file_path(char *old_path, char *new_path); +extern int update_file_path(const char *old_path, const char *new_path); /** * @ingroup fs diff --git a/fs/jffs2/src/vfs_jffs2.c b/fs/jffs2/src/vfs_jffs2.c index e74b2c852d839e1b904c74b8fd3018b02f2422ec..97596027bca954623b4fdaecce9a73f222cb7fc0 100755 --- a/fs/jffs2/src/vfs_jffs2.c +++ b/fs/jffs2/src/vfs_jffs2.c @@ -470,7 +470,7 @@ int VfsJffs2Readdir(struct Vnode *pVnode, struct fs_dirent_s *dir) LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER); /* set jffs2_d */ - while (i < MAX_DIRENT_NUM && i < dir->read_cnt) { + while (i < dir->read_cnt) { ret = jffs2_readdir((struct jffs2_inode *)pVnode->data, &dir->fd_position, &dir->fd_int_offset, &dir->fd_dir[i]); if (ret) { diff --git a/fs/proc/os_adapt/proc_vfs.c b/fs/proc/os_adapt/proc_vfs.c index 3e3374f7bc93834a4a6c723d8c9b1144165f5b59..87412b1141c02a5d7a04ff3bf74e0ec5418ed909 100755 --- a/fs/proc/os_adapt/proc_vfs.c +++ b/fs/proc/os_adapt/proc_vfs.c @@ -182,7 +182,7 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir) } pde = VnodeToEntry(node); - while ((i < MAX_DIRENT_NUM) || (i < dir->read_cnt)) { + while (i < dir->read_cnt) { buffer = (char *)zalloc(sizeof(char) * NAME_MAX); if (buffer == NULL) { PRINT_ERR("malloc failed\n"); diff --git a/fs/vfs/disk/disk.c b/fs/vfs/disk/disk.c index 43588d84410f6a2100d633053b3d3f80ee22fe3e..433dd5eae3c82a907623bb236b2ebb8108a90ade 100755 --- a/fs/vfs/disk/disk.c +++ b/fs/vfs/disk/disk.c @@ -696,9 +696,13 @@ static INT32 DiskPartitionRecognition(struct Vnode *blkDrv, struct disk_divide_i CHAR *mbrBuf = NULL; CHAR *ebrBuf = NULL; + if (blkDrv == NULL) { + return -EINVAL; + } + struct block_operations *bops = (struct block_operations *)((struct drv_data *)blkDrv->data)->ops; - if ((blkDrv == NULL) || (bops == NULL) || (bops->read == NULL)) { + if ((bops == NULL) || (bops->read == NULL)) { return -EINVAL; } @@ -832,8 +836,11 @@ INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count) } } else { #endif + if (disk->dev == NULL) { + goto ERROR_HANDLE; + } struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops; - if ((disk->dev != NULL) && (bops != NULL) && (bops->read != NULL)) { + if ((bops != NULL) && (bops->read != NULL)) { result = bops->read(disk->dev, (UINT8 *)buf, sector, count); if (result == (INT32)count) { result = ENOERR; diff --git a/fs/vfs/operation/fs_file_mapping.c b/fs/vfs/operation/fs_file_mapping.c index a8f6b1f79ee978d43ac547fd945f78fd9aa80d73..22cbca4f93abef04cd945d3ed807655ecadbdf0c 100644 --- a/fs/vfs/operation/fs_file_mapping.c +++ b/fs/vfs/operation/fs_file_mapping.c @@ -245,7 +245,7 @@ out: (VOID)LOS_MuxUnlock(&g_file_mapping.lock); } -int update_file_path(char *old_path, char *new_path) +int update_file_path(const char *old_path, const char *new_path) { unsigned int i = 3; struct filelist *f_list = NULL; @@ -262,10 +262,10 @@ int update_file_path(char *old_path, char *new_path) (VOID)LOS_MuxLock(&g_file_mapping.lock, LOS_WAIT_FOREVER); while (i < CONFIG_NFILE_DESCRIPTORS) { i++; - if (!get_bit(i)) { + if (!get_bit(i - 1)) { continue; } - filp = &tg_filelist.fl_files[i]; + filp = &tg_filelist.fl_files[i - 1]; if (filp->f_path == NULL || strcmp(filp->f_path, old_path)) { continue; } diff --git a/fs/vfs/path_cache.c b/fs/vfs/path_cache.c index 6242f7dc0d2ecad7942abed5940d85386a50ff8d..ab279104726856844b3c54367c64a2889b118228 100755 --- a/fs/vfs/path_cache.c +++ b/fs/vfs/path_cache.c @@ -93,6 +93,7 @@ struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, cons { struct PathCache *nc = NULL; size_t pathCacheSize; + int ret; if (name == NULL || len > NAME_MAX || parent == NULL || vnode == NULL) { return NULL; @@ -105,7 +106,10 @@ struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, cons return NULL; } - (void)strncpy_s(nc->name, pathCacheSize, name, len); + ret = strncpy_s(nc->name, pathCacheSize, name, len); + if (ret != LOS_OK) { + return NULL; + } nc->parentVnode = parent; nc->nameLen = len; diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index a2cf65755916fff718e6a139f33403fce10ab7b1..0293cfd09d10abea52bfe9a9f51c56ac3695855f 100755 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -573,6 +573,10 @@ int VnodeDevInit() devNode->type = VNODE_TYPE_DIR; devMount = MountAlloc(devNode, NULL); + if (devMount == NULL) { + PRINT_ERR("VnodeDevInit failed mount point alloc failed.\n"); + return -ENOMEM; + } devMount->vnodeCovered = devNode; devMount->vnodeBeCovered->flag |= VNODE_FLAG_MOUNT_NEW; return LOS_OK;