mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 20:08:15 +08:00
fs/hostfs: Replace strcpy with memcpy
The strcpy function is dangerous because it does not check the length of the Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
+4
-2
@@ -246,6 +246,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
FAR struct hostfs_mountpt_s *fs;
|
FAR struct hostfs_mountpt_s *fs;
|
||||||
FAR struct hostfs_ofile_s *hf;
|
FAR struct hostfs_ofile_s *hf;
|
||||||
char path[HOSTFS_MAX_PATH];
|
char path[HOSTFS_MAX_PATH];
|
||||||
|
size_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
@@ -271,7 +272,8 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
|
|
||||||
/* Allocate memory for the open file */
|
/* 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)
|
if (hf == NULL)
|
||||||
{
|
{
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
@@ -323,7 +325,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
hf->fnext = fs->fs_head;
|
hf->fnext = fs->fs_head;
|
||||||
hf->crefs = 1;
|
hf->crefs = 1;
|
||||||
hf->oflags = oflags;
|
hf->oflags = oflags;
|
||||||
strcpy(hf->relpath, relpath);
|
memcpy(hf->relpath, relpath, len + 1);
|
||||||
fs->fs_head = hf;
|
fs->fs_head = hf;
|
||||||
|
|
||||||
ret = OK;
|
ret = OK;
|
||||||
|
|||||||
Reference in New Issue
Block a user