nuttx:Change fs strncpy to strlcpy to avoid losing'\0'

Signed-off-by: zhouliang3 <zhouliang3@xiaomi.com>
This commit is contained in:
zhouliang3
2021-12-29 20:17:34 +08:00
committed by Xiang Xiao
parent 76b2f7199d
commit 1f53a058fa
20 changed files with 60 additions and 55 deletions
+17 -11
View File
@@ -604,7 +604,8 @@ static int smartfs_closedir(FAR struct fs_dirent_s *dir)
static int smartfs_readdir(struct fs_dirent_s *dir)
{
FAR struct smartfs_level1_s *level1;
int ret, index;
int ret;
int index;
DEBUGASSERT(dir && dir->u.procfs);
level1 = dir->u.procfs;
@@ -640,8 +641,8 @@ 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);
strlcpy(dir->fd_dir.d_name, level1->mount->fs_blkdriver->i_name,
sizeof(dir->fd_dir.d_name));
/* Advance to next entry */
@@ -653,16 +654,16 @@ static int smartfs_readdir(struct fs_dirent_s *dir)
/* Listing the contents of a specific mount */
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);
strlcpy(dir->fd_dir.d_name, g_direntry[level1->base.index++].name,
sizeof(dir->fd_dir.d_name));
}
else if (level1->base.level == 3)
{
/* Listing the contents of a specific entry */
dir->fd_dir.d_type = g_direntry[level1->base.index].type;
strncpy(dir->fd_dir.d_name, g_direntry[level1->direntry].name,
NAME_MAX);
strlcpy(dir->fd_dir.d_name, g_direntry[level1->direntry].name,
sizeof(dir->fd_dir.d_name));
level1->base.index++;
}
@@ -874,7 +875,8 @@ static size_t smartfs_mem_read(FAR struct file *filep, FAR char *buffer,
FAR struct smartfs_file_s *priv;
int ret;
uint16_t x;
size_t len, total;
size_t len;
size_t total;
priv = (FAR struct smartfs_file_s *) filep->f_priv;
@@ -938,9 +940,13 @@ static size_t smartfs_erasemap_read(FAR struct file *filep,
{
struct mtd_smart_procfs_data_s procfs_data;
FAR struct smartfs_file_s *priv;
int ret, rows, cols;
size_t x, y;
size_t len, copylen;
int ret;
int rows;
int cols;
size_t x;
size_t y;
size_t len;
size_t copylen;
priv = (FAR struct smartfs_file_s *) filep->f_priv;
+2 -9
View File
@@ -1272,7 +1272,6 @@ static int smartfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
struct smartfs_mountpt_s *fs;
int ret;
uint16_t entrysize;
uint16_t namelen;
struct smartfs_chain_header_s *header;
struct smart_read_write_s readwrite;
struct smartfs_entry_header_s *entry;
@@ -1350,14 +1349,8 @@ static int smartfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
/* Copy the entry name to dirent */
namelen = fs->fs_llformat.namesize;
if (namelen > NAME_MAX)
{
namelen = NAME_MAX;
}
memset(dir->fd_dir.d_name, 0, namelen);
strncpy(dir->fd_dir.d_name, entry->name, namelen);
strlcpy(dir->fd_dir.d_name, entry->name,
sizeof(dir->fd_dir.d_name));
/* Now advance to the next entry */