fs/readdir: Must reserve a byte for the NUL terminator

Change-Id: I1df0c278d289b90cc54512c0ee256a95549785ca
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2021-01-16 16:58:18 +08:00 committed by Xiang Xiao
parent f63e1e277f
commit 13100cf248
10 changed files with 13 additions and 13 deletions

View File

@ -334,7 +334,7 @@ static int binfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
finfo("Entry %d: \"%s\"\n", index, name);
dir->fd_dir.d_type = DTYPE_FILE;
strncpy(dir->fd_dir.d_name, name, NAME_MAX + 1);
strncpy(dir->fd_dir.d_name, name, NAME_MAX);
/* The application list is terminated by an entry with a NULL name.
* Therefore, there is at least one more entry in the list.

View File

@ -1285,7 +1285,7 @@ static int cromfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
name = (FAR char *)cromfs_offset2addr(fs, node->cn_name);
finfo("Entry %lu: %s\n", (unsigned long)offset, name);
strncpy(dir->fd_dir.d_name, name, NAME_MAX + 1);
strncpy(dir->fd_dir.d_name, name, NAME_MAX);
switch (node->cn_mode & S_IFMT)
{

View File

@ -61,7 +61,7 @@ static inline int readpseudodir(struct fs_dirent_s *idir)
/* Copy the inode name into the dirent structure */
strncpy(idir->fd_dir.d_name, idir->u.pseudo.fd_next->i_name,
NAME_MAX + 1);
NAME_MAX);
/* If the node has file operations, we will say that it is a file. */

View File

@ -150,7 +150,7 @@ int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir)
finfo("Offset %jd: \"%s\"\n", (intmax_t)entry.hoffset, entry.name);
dir->fd_dir.d_type = DTYPE_FILE;
strncpy(dir->fd_dir.d_name, entry.name, NAME_MAX + 1);
strncpy(dir->fd_dir.d_name, entry.name, NAME_MAX);
/* Discard this entry and set the next offset. */

View File

@ -1756,7 +1756,7 @@ static int proc_readdir(struct fs_dirent_s *dir)
/* Save the filename and file type */
dir->fd_dir.d_type = node->dtype;
strncpy(dir->fd_dir.d_name, node->name, NAME_MAX + 1);
strncpy(dir->fd_dir.d_name, node->name, NAME_MAX);
/* Set up the next directory entry offset. NOTE that we could use the
* standard f_pos instead of our own private index.

View File

@ -456,7 +456,7 @@ static int skel_readdir(FAR struct fs_dirent_s *dir)
/* TODO: Specify the type of entry */
dir->fd_dir.d_type = DTYPE_FILE;
strncpy(dir->fd_dir.d_name, filename, NAME_MAX + 1);
strncpy(dir->fd_dir.d_name, filename, NAME_MAX);
/* Set up the next directory entry offset. NOTE that we could use the
* standard f_pos instead of our own private index.

View File

@ -656,7 +656,7 @@ static int smartfs_readdir(struct fs_dirent_s *dir)
dir->fd_dir.d_type = DTYPE_DIRECTORY;
strncpy(dir->fd_dir.d_name, level1->mount->fs_blkdriver->i_name,
NAME_MAX + 1);
NAME_MAX);
/* Advance to next entry */
@ -669,7 +669,7 @@ static int smartfs_readdir(struct fs_dirent_s *dir)
dir->fd_dir.d_type = g_direntry[level1->base.index].type;
strncpy(dir->fd_dir.d_name, g_direntry[level1->base.index++].name,
NAME_MAX + 1);
NAME_MAX);
}
else if (level1->base.level == 3)
{
@ -677,7 +677,7 @@ static int smartfs_readdir(struct fs_dirent_s *dir)
dir->fd_dir.d_type = g_direntry[level1->base.index].type;
strncpy(dir->fd_dir.d_name, g_direntry[level1->direntry].name,
NAME_MAX + 1);
NAME_MAX);
level1->base.index++;
}

View File

@ -341,7 +341,7 @@ static int spiffs_readdir_callback(FAR struct spiffs_s *fs,
strncpy(entryp->d_name,
(FAR char *)objhdr.name + SPIFFS_LEADING_SLASH_SIZE,
NAME_MAX + 1);
NAME_MAX);
entryp->d_type = objhdr.type;
return OK;
}

View File

@ -2057,7 +2057,7 @@ static int tmpfs_readdir(FAR struct inode *mountpt,
/* Copy the entry name */
strncpy(dir->fd_dir.d_name, tde->tde_name, NAME_MAX + 1);
strncpy(dir->fd_dir.d_name, tde->tde_name, NAME_MAX);
/* Save the index for next time */

View File

@ -1629,7 +1629,7 @@ static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
* directories.
*/
strncpy(dir->fd_dir.d_name, um->um_prefix, NAME_MAX + 1);
strncpy(dir->fd_dir.d_name, um->um_prefix, NAME_MAX);
/* Describe this as a read only directory */
@ -1703,7 +1703,7 @@ static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
* be multiple directories.
*/
strncpy(dir->fd_dir.d_name, um->um_prefix, NAME_MAX + 1);
strncpy(dir->fd_dir.d_name, um->um_prefix, NAME_MAX);
/* Describe this as a read only directory */