Skip to content

Commit 08ababd

Browse files
xiaoxiang781216jerpelea
authored andcommitted
fs/vfs: Add a new argument(size_t len) to inode_getpath
Signed-off-by: Xiang Xiao <[email protected]>
1 parent 0f243bd commit 08ababd

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

fs/binfs/fs_binfs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,14 @@ static int binfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
224224
}
225225
else
226226
{
227-
ret = inode_getpath(filep->f_inode, ptr);
227+
ret = inode_getpath(filep->f_inode, ptr, PATH_MAX);
228228
if (ret < 0)
229229
{
230230
return ret;
231231
}
232232

233-
strcat(ptr, builtin_getname((int)((uintptr_t)filep->f_priv)));
233+
strlcat(ptr, builtin_getname((int)((uintptr_t)filep->f_priv)),
234+
PATH_MAX);
234235
}
235236
}
236237
else

fs/inode/fs_inodegetpath.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
****************************************************************************/
4444

45-
int inode_getpath(FAR struct inode *node, FAR char *path)
45+
int inode_getpath(FAR struct inode *node, FAR char *path, size_t len)
4646
{
4747
if (path == NULL)
4848
{
@@ -55,17 +55,17 @@ int inode_getpath(FAR struct inode *node, FAR char *path)
5555
}
5656
else
5757
{
58-
int ret = inode_getpath(node->i_parent, path);
58+
int ret = inode_getpath(node->i_parent, path, len);
5959
if (ret < 0)
6060
{
6161
return ret;
6262
}
6363
}
6464

65-
strcat(path, node->i_name);
65+
strlcat(path, node->i_name, len);
6666
if (node->i_child || INODE_IS_MOUNTPT(node))
6767
{
68-
strcat(path, "/");
68+
strlcat(path, "/", len);
6969
}
7070

7171
return OK;

fs/inode/inode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ int inode_chstat(FAR struct inode *inode,
279279
*
280280
****************************************************************************/
281281

282-
int inode_getpath(FAR struct inode *node, FAR char *path);
282+
int inode_getpath(FAR struct inode *node, FAR char *path, size_t len);
283283

284284
/****************************************************************************
285285
* Name: inode_free

fs/romfs/fs_romfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
599599
if (cmd == FIOC_FILEPATH)
600600
{
601601
FAR char *ptr = (FAR char *)((uintptr_t)arg);
602-
inode_getpath(filep->f_inode, ptr);
603-
strcat(ptr, rf->rf_path);
602+
inode_getpath(filep->f_inode, ptr, PATH_MAX);
603+
strlcat(ptr, rf->rf_path, PATH_MAX);
604604
return OK;
605605
}
606606

fs/vfs/fs_dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath)
599599
}
600600
}
601601

602-
inode_getpath(inode, path_prefix);
602+
inode_getpath(inode, path_prefix, sizeof(path_prefix));
603603
ret = asprintf(&dir->fd_path, "%s%s/", path_prefix, relpath);
604604
if (ret < 0)
605605
{

fs/vfs/fs_ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap)
105105
case FIOC_FILEPATH:
106106
if (ret == -ENOTTY && !INODE_IS_MOUNTPT(inode))
107107
{
108-
ret = inode_getpath(inode, (FAR char *)(uintptr_t)arg);
108+
ret = inode_getpath(inode, (FAR char *)(uintptr_t)arg, PATH_MAX);
109109
}
110110
break;
111111

0 commit comments

Comments
 (0)