Skip to content

Commit 659448a

Browse files
xiaoxiang781216GUIDINGLI
authored andcommitted
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 <[email protected]>
1 parent 4435195 commit 659448a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/hostfs/hostfs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
246246
FAR struct hostfs_mountpt_s *fs;
247247
FAR struct hostfs_ofile_s *hf;
248248
char path[HOSTFS_MAX_PATH];
249+
size_t len;
249250
int ret;
250251

251252
/* Sanity checks */
@@ -271,7 +272,8 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
271272

272273
/* Allocate memory for the open file */
273274

274-
hf = kmm_malloc(sizeof(*hf) + strlen(relpath));
275+
len = strlen(relpath);
276+
hf = kmm_malloc(sizeof(*hf) + len);
275277
if (hf == NULL)
276278
{
277279
ret = -ENOMEM;
@@ -323,7 +325,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
323325
hf->fnext = fs->fs_head;
324326
hf->crefs = 1;
325327
hf->oflags = oflags;
326-
strcpy(hf->relpath, relpath);
328+
memcpy(hf->relpath, relpath, len + 1);
327329
fs->fs_head = hf;
328330

329331
ret = OK;

0 commit comments

Comments
 (0)