diff --git a/libs/libc/libc.h b/libs/libc/libc.h index 7a81e44549..897e1f7df3 100644 --- a/libs/libc/libc.h +++ b/libs/libc/libc.h @@ -83,7 +83,8 @@ FAR char *__dtoa(double d, int mode, int ndigits, FAR int *decpt, /* Defined in lib_getfullpath.c */ -int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath); +int lib_getfullpath(int dirfd, FAR const char *path, + FAR char *fullpath, size_t fulllen); /* Defined in lib_fopen.c */ diff --git a/libs/libc/misc/lib_fchmodat.c b/libs/libc/misc/lib_fchmodat.c index 7ebb47c966..c2a96817fb 100644 --- a/libs/libc/misc/lib_fchmodat.c +++ b/libs/libc/misc/lib_fchmodat.c @@ -67,7 +67,7 @@ int fchmodat(int dirfd, FAR const char *path, mode_t mode, int flags) char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/misc/lib_fstatat.c b/libs/libc/misc/lib_fstatat.c index af64110f3d..99003aa4bb 100644 --- a/libs/libc/misc/lib_fstatat.c +++ b/libs/libc/misc/lib_fstatat.c @@ -68,7 +68,7 @@ int fstatat(int dirfd, FAR const char *path, FAR struct stat *buf, char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/misc/lib_getfullpath.c b/libs/libc/misc/lib_getfullpath.c index 1cd454c38e..7e457c71a8 100644 --- a/libs/libc/misc/lib_getfullpath.c +++ b/libs/libc/misc/lib_getfullpath.c @@ -42,7 +42,8 @@ * ****************************************************************************/ -int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath) +int lib_getfullpath(int dirfd, FAR const char *path, + FAR char *fullpath, size_t fulllen) { if (path == NULL || fullpath == NULL) { @@ -52,7 +53,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath) { /* The path is absolute, then dirfd is ignored. */ - strlcpy(fullpath, path, PATH_MAX); + strlcpy(fullpath, path, fulllen); return 0; } @@ -73,7 +74,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath) } #endif - sprintf(fullpath, "%s/%s", pwd, path); + snprintf(fullpath, fulllen, "%s/%s", pwd, path); return 0; } else @@ -85,7 +86,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath) ret = fcntl(dirfd, F_GETPATH, fullpath); if (ret >= 0) { - strlcat(fullpath, path, PATH_MAX); + strlcat(fullpath, path, fulllen); } return 0; diff --git a/libs/libc/misc/lib_mkdirat.c b/libs/libc/misc/lib_mkdirat.c index 9932f900ee..db99dbdb66 100644 --- a/libs/libc/misc/lib_mkdirat.c +++ b/libs/libc/misc/lib_mkdirat.c @@ -65,7 +65,7 @@ int mkdirat(int dirfd, FAR const char *path, mode_t mode) char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/misc/lib_mkfifo.c b/libs/libc/misc/lib_mkfifo.c index 5999fb39f4..bbe3551ef0 100644 --- a/libs/libc/misc/lib_mkfifo.c +++ b/libs/libc/misc/lib_mkfifo.c @@ -115,7 +115,7 @@ int mkfifoat(int dirfd, FAR const char *path, mode_t mode) char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/misc/lib_mknod.c b/libs/libc/misc/lib_mknod.c index 205300a91b..c4a3bb859f 100644 --- a/libs/libc/misc/lib_mknod.c +++ b/libs/libc/misc/lib_mknod.c @@ -135,7 +135,7 @@ int mknodat(int dirfd, FAR const char *path, mode_t mode, dev_t dev) char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/misc/lib_openat.c b/libs/libc/misc/lib_openat.c index 20be9bb916..9ce18d7350 100644 --- a/libs/libc/misc/lib_openat.c +++ b/libs/libc/misc/lib_openat.c @@ -67,7 +67,7 @@ int openat(int dirfd, FAR const char *path, int oflags, ...) mode_t mode = 0; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/misc/lib_utimensat.c b/libs/libc/misc/lib_utimensat.c index 2fed37d87f..989bd8ea94 100644 --- a/libs/libc/misc/lib_utimensat.c +++ b/libs/libc/misc/lib_utimensat.c @@ -67,7 +67,7 @@ int utimensat(int dirfd, FAR const char *path, char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/stdio/lib_renameat.c b/libs/libc/stdio/lib_renameat.c index 12bd24cd41..99abe268a6 100644 --- a/libs/libc/stdio/lib_renameat.c +++ b/libs/libc/stdio/lib_renameat.c @@ -72,10 +72,12 @@ int renameat(int olddirfd, FAR const char *oldpath, char newfullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(olddirfd, oldpath, oldfullpath); + ret = lib_getfullpath(olddirfd, oldpath, + oldfullpath, sizeof(oldfullpath)); if (ret >= 0) { - ret = lib_getfullpath(newdirfd, newpath, newfullpath); + ret = lib_getfullpath(newdirfd, newpath, + newfullpath, sizeof(newfullpath)); } if (ret < 0) diff --git a/libs/libc/unistd/lib_access.c b/libs/libc/unistd/lib_access.c index da35dbc992..d35abcdcac 100644 --- a/libs/libc/unistd/lib_access.c +++ b/libs/libc/unistd/lib_access.c @@ -138,7 +138,7 @@ int faccessat(int dirfd, FAR const char *path, int amode, int flags) char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/unistd/lib_fchownat.c b/libs/libc/unistd/lib_fchownat.c index db3b26c91a..a140c669de 100644 --- a/libs/libc/unistd/lib_fchownat.c +++ b/libs/libc/unistd/lib_fchownat.c @@ -69,7 +69,7 @@ int fchownat(int dirfd, FAR const char *path, uid_t owner, char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/unistd/lib_linkat.c b/libs/libc/unistd/lib_linkat.c index 4c2a8530cc..f0b252095f 100644 --- a/libs/libc/unistd/lib_linkat.c +++ b/libs/libc/unistd/lib_linkat.c @@ -80,10 +80,12 @@ int linkat(int olddirfd, FAR const char *path1, char newfullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(olddirfd, path1, oldfullpath); + ret = lib_getfullpath(olddirfd, path1, + oldfullpath, sizeof(oldfullpath)); if (ret >= 0) { - ret = lib_getfullpath(newdirfd, path2, newfullpath); + ret = lib_getfullpath(newdirfd, path2, + newfullpath, sizeof(newfullpath)); } if (ret < 0) diff --git a/libs/libc/unistd/lib_readlinkat.c b/libs/libc/unistd/lib_readlinkat.c index fe911dd619..85e863b9aa 100644 --- a/libs/libc/unistd/lib_readlinkat.c +++ b/libs/libc/unistd/lib_readlinkat.c @@ -71,7 +71,7 @@ ssize_t readlinkat(int dirfd, FAR const char *path, FAR char *buf, char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/unistd/lib_symlinkat.c b/libs/libc/unistd/lib_symlinkat.c index 33d6698eed..6a6d6ee9c1 100644 --- a/libs/libc/unistd/lib_symlinkat.c +++ b/libs/libc/unistd/lib_symlinkat.c @@ -68,7 +68,7 @@ int symlinkat(FAR const char *path1, int dirfd, FAR const char *path2) char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path2, fullpath); + ret = lib_getfullpath(dirfd, path2, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/unistd/lib_unlinkat.c b/libs/libc/unistd/lib_unlinkat.c index 4ceb3c8950..cde938743b 100644 --- a/libs/libc/unistd/lib_unlinkat.c +++ b/libs/libc/unistd/lib_unlinkat.c @@ -69,7 +69,7 @@ int unlinkat(int dirfd, FAR const char *path, int flags) char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret); diff --git a/libs/libc/unistd/lib_utimes.c b/libs/libc/unistd/lib_utimes.c index d115aec7c5..16e2945117 100644 --- a/libs/libc/unistd/lib_utimes.c +++ b/libs/libc/unistd/lib_utimes.c @@ -54,7 +54,7 @@ int futimesat(int dirfd, FAR const char *path, const struct timeval tv[2]) char fullpath[PATH_MAX]; int ret; - ret = lib_getfullpath(dirfd, path, fullpath); + ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { set_errno(-ret);