Skip to content

Commit

Permalink
fs/hostfs: Replace strcpy with memcpy
Browse files Browse the repository at this point in the history
The strcpy function is dangerous because it does not check the length of the

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 committed Aug 18, 2024
1 parent f7adb52 commit 45405f8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fs/hostfs/hostfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
FAR struct hostfs_mountpt_s *fs;
FAR struct hostfs_ofile_s *hf;
char path[HOSTFS_MAX_PATH];
size_t len;
int ret;

/* Sanity checks */
Expand All @@ -270,7 +271,8 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,

/* Allocate memory for the open file */

hf = kmm_malloc(sizeof(*hf) + strlen(relpath));
len = strlen(relpath)
hf = kmm_malloc(sizeof(*hf) + len);
if (hf == NULL)
{
ret = -ENOMEM;
Expand Down Expand Up @@ -322,7 +324,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
hf->fnext = fs->fs_head;
hf->crefs = 1;
hf->oflags = oflags;
strcpy(hf->relpath, relpath);
memcpy(hf->relpath, relpath, len + 1);
fs->fs_head = hf;

ret = OK;
Expand Down

0 comments on commit 45405f8

Please sign in to comment.