Skip to content

Commit 6354a74

Browse files
xiaoxiang781216jerpelea
authored andcommitted
libc: Add a new argument(size_t fulllen) to lib_getfullpath
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent 08ababd commit 6354a74

17 files changed

+28
-22
lines changed

libs/libc/libc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ FAR char *__dtoa(double d, int mode, int ndigits, FAR int *decpt,
8383

8484
/* Defined in lib_getfullpath.c */
8585

86-
int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath);
86+
int lib_getfullpath(int dirfd, FAR const char *path,
87+
FAR char *fullpath, size_t fulllen);
8788

8889
/* Defined in lib_fopen.c */
8990

libs/libc/misc/lib_fchmodat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int fchmodat(int dirfd, FAR const char *path, mode_t mode, int flags)
6767
char fullpath[PATH_MAX];
6868
int ret;
6969

70-
ret = lib_getfullpath(dirfd, path, fullpath);
70+
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
7171
if (ret < 0)
7272
{
7373
set_errno(-ret);

libs/libc/misc/lib_fstatat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int fstatat(int dirfd, FAR const char *path, FAR struct stat *buf,
6868
char fullpath[PATH_MAX];
6969
int ret;
7070

71-
ret = lib_getfullpath(dirfd, path, fullpath);
71+
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
7272
if (ret < 0)
7373
{
7474
set_errno(-ret);

libs/libc/misc/lib_getfullpath.c

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

45-
int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath)
45+
int lib_getfullpath(int dirfd, FAR const char *path,
46+
FAR char *fullpath, size_t fulllen)
4647
{
4748
if (path == NULL || fullpath == NULL)
4849
{
@@ -52,7 +53,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath)
5253
{
5354
/* The path is absolute, then dirfd is ignored. */
5455

55-
strlcpy(fullpath, path, PATH_MAX);
56+
strlcpy(fullpath, path, fulllen);
5657
return 0;
5758
}
5859

@@ -73,7 +74,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath)
7374
}
7475
#endif
7576

76-
sprintf(fullpath, "%s/%s", pwd, path);
77+
snprintf(fullpath, fulllen, "%s/%s", pwd, path);
7778
return 0;
7879
}
7980
else
@@ -85,7 +86,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath)
8586
ret = fcntl(dirfd, F_GETPATH, fullpath);
8687
if (ret >= 0)
8788
{
88-
strlcat(fullpath, path, PATH_MAX);
89+
strlcat(fullpath, path, fulllen);
8990
}
9091

9192
return 0;

libs/libc/misc/lib_mkdirat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int mkdirat(int dirfd, FAR const char *path, mode_t mode)
6565
char fullpath[PATH_MAX];
6666
int ret;
6767

68-
ret = lib_getfullpath(dirfd, path, fullpath);
68+
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
6969
if (ret < 0)
7070
{
7171
set_errno(-ret);

libs/libc/misc/lib_mkfifo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int mkfifoat(int dirfd, FAR const char *path, mode_t mode)
115115
char fullpath[PATH_MAX];
116116
int ret;
117117

118-
ret = lib_getfullpath(dirfd, path, fullpath);
118+
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
119119
if (ret < 0)
120120
{
121121
set_errno(-ret);

libs/libc/misc/lib_mknod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ int mknodat(int dirfd, FAR const char *path, mode_t mode, dev_t dev)
135135
char fullpath[PATH_MAX];
136136
int ret;
137137

138-
ret = lib_getfullpath(dirfd, path, fullpath);
138+
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
139139
if (ret < 0)
140140
{
141141
set_errno(-ret);

libs/libc/misc/lib_openat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int openat(int dirfd, FAR const char *path, int oflags, ...)
6767
mode_t mode = 0;
6868
int ret;
6969

70-
ret = lib_getfullpath(dirfd, path, fullpath);
70+
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
7171
if (ret < 0)
7272
{
7373
set_errno(-ret);

libs/libc/misc/lib_utimensat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int utimensat(int dirfd, FAR const char *path,
6767
char fullpath[PATH_MAX];
6868
int ret;
6969

70-
ret = lib_getfullpath(dirfd, path, fullpath);
70+
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
7171
if (ret < 0)
7272
{
7373
set_errno(-ret);

libs/libc/stdio/lib_renameat.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ int renameat(int olddirfd, FAR const char *oldpath,
7272
char newfullpath[PATH_MAX];
7373
int ret;
7474

75-
ret = lib_getfullpath(olddirfd, oldpath, oldfullpath);
75+
ret = lib_getfullpath(olddirfd, oldpath,
76+
oldfullpath, sizeof(oldfullpath));
7677
if (ret >= 0)
7778
{
78-
ret = lib_getfullpath(newdirfd, newpath, newfullpath);
79+
ret = lib_getfullpath(newdirfd, newpath,
80+
newfullpath, sizeof(newfullpath));
7981
}
8082

8183
if (ret < 0)

0 commit comments

Comments
 (0)