From 2cf26036a5d7ec995c2edf04aa94cf07e9870883 Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Wed, 9 Oct 2024 12:14:18 +0800 Subject: [PATCH] Use lib_get_pathbuffer instead of stack variables Summary: Modified the usage logic, mainly introduced lib_get_pathbuffer and lib_put_pathbuffer Signed-off-by: chenrun1 --- arch/risc-v/src/common/espressif/esp_timer.c | 13 ++- drivers/input/aw86225.c | 12 +- drivers/mtd/dhara.c | 16 ++- drivers/sensors/gnss_uorb.c | 21 +++- drivers/sensors/sensor.c | 25 +++- fs/inode/fs_files.c | 11 +- fs/mount/fs_automount.c | 19 +++- fs/partition/fs_partition.c | 12 +- fs/procfs/fs_procfsproc.c | 11 +- fs/rpmsgfs/rpmsgfs.c | 114 +++++++++++++++---- fs/v9fs/client.c | 18 ++- fs/vfs/fs_dir.c | 15 ++- libs/libc/locale/lib_catalog.c | 13 ++- libs/libc/locale/lib_gettext.c | 11 +- libs/libc/misc/lib_fchmodat.c | 21 +++- libs/libc/misc/lib_fstatat.c | 21 +++- libs/libc/misc/lib_ftok.c | 13 ++- libs/libc/misc/lib_glob.c | 10 +- libs/libc/misc/lib_memfd.c | 13 ++- libs/libc/misc/lib_mkdirat.c | 16 ++- libs/libc/misc/lib_mkfifo.c | 16 ++- libs/libc/misc/lib_mknod.c | 16 ++- libs/libc/misc/lib_openat.c | 16 ++- libs/libc/misc/lib_utimensat.c | 21 +++- libs/libc/stdio/lib_renameat.c | 30 ++++- libs/libc/unistd/lib_access.c | 16 ++- libs/libc/unistd/lib_fchdir.c | 16 ++- libs/libc/unistd/lib_fchownat.c | 21 +++- libs/libc/unistd/lib_linkat.c | 30 ++++- libs/libc/unistd/lib_readlinkat.c | 16 ++- libs/libc/unistd/lib_symlinkat.c | 16 ++- libs/libc/unistd/lib_unlinkat.c | 21 +++- libs/libc/unistd/lib_utimes.c | 16 ++- 33 files changed, 545 insertions(+), 111 deletions(-) diff --git a/arch/risc-v/src/common/espressif/esp_timer.c b/arch/risc-v/src/common/espressif/esp_timer.c index 1e9dd861d8..860393fd22 100644 --- a/arch/risc-v/src/common/espressif/esp_timer.c +++ b/arch/risc-v/src/common/espressif/esp_timer.c @@ -31,6 +31,7 @@ #include #include +#include #include "esp_irq.h" #include "esp_timer.h" @@ -508,7 +509,7 @@ IRAM_ATTR static int esp_timer_isr(int irq, void *context, void *arg) int esp_timer_initialize(uint32_t timer_id) { struct esp_timer_lowerhalf_s *lower = NULL; - char devpath[PATH_MAX]; + FAR char *devpath; uint32_t group_num; uint32_t timer_num; @@ -539,7 +540,13 @@ int esp_timer_initialize(uint32_t timer_id) break; } - snprintf(devpath, sizeof(devpath), "/dev/timer%" PRIu32, timer_id); + devpath = lib_get_pathbuffer(); + if (devpath == NULL) + { + return -ENOMEM; + } + + snprintf(devpath, PATH_MAX, "/dev/timer%" PRIu32, timer_id); /* Initialize the elements of lower half state structure */ @@ -562,9 +569,11 @@ int esp_timer_initialize(uint32_t timer_id) * indicate the failure (implying the non-unique devpath). */ + lib_put_pathbuffer(devpath); return -EEXIST; } + lib_put_pathbuffer(devpath); esp_setup_irq(lower->source, ESP_IRQ_PRIORITY_DEFAULT, ESP_IRQ_TRIGGER_LEVEL); diff --git a/drivers/input/aw86225.c b/drivers/input/aw86225.c index 0d71d2e162..3816fe3003 100644 --- a/drivers/input/aw86225.c +++ b/drivers/input/aw86225.c @@ -47,6 +47,7 @@ #include #include #include +#include #include "aw86225_reg.h" #include "aw86225_internal.h" @@ -369,14 +370,21 @@ static int aw86225_i2c_write_bits(FAR struct aw86225 *aw86225, static int aw86225_request_firmware(FAR struct aw86225_firmware *fw, FAR const char *filename) { - char file_path[PATH_MAX]; + FAR char *file_path; struct file file; size_t file_size; int ret; - snprintf(file_path, sizeof(file_path), "%s/%s", CONFIG_FF_RTP_FILE_PATH, + file_path = lib_get_pathbuffer(); + if (file_path == NULL) + { + return -ENOMEM; + } + + snprintf(file_path, PATH_MAX, "%s/%s", CONFIG_FF_RTP_FILE_PATH, filename); ret = file_open(&file, file_path, O_RDONLY); + lib_put_pathbuffer(file_path); if (ret < 0) { ierr("open file failed"); diff --git a/drivers/mtd/dhara.c b/drivers/mtd/dhara.c index 0f485be85c..550572b697 100644 --- a/drivers/mtd/dhara.c +++ b/drivers/mtd/dhara.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -785,7 +786,8 @@ err: int dhara_initialize(int minor, FAR struct mtd_dev_s *mtd) { - char path[PATH_MAX]; + FAR char *path; + int ret; #ifdef CONFIG_DEBUG_FEATURES /* Sanity check */ @@ -796,8 +798,16 @@ int dhara_initialize(int minor, FAR struct mtd_dev_s *mtd) } #endif + path = lib_get_pathbuffer(); + if (path == NULL) + { + return -ENOMEM; + } + /* Do the real work by dhara_mtdblock_initialize_by_path */ - snprintf(path, sizeof(path), "/dev/mtdblock%d", minor); - return dhara_initialize_by_path(path, mtd); + snprintf(path, PATH_MAX, "/dev/mtdblock%d", minor); + ret = dhara_initialize_by_path(path, mtd); + lib_put_pathbuffer(path); + return ret; } diff --git a/drivers/sensors/gnss_uorb.c b/drivers/sensors/gnss_uorb.c index 87e8a6626a..d33c11a49c 100644 --- a/drivers/sensors/gnss_uorb.c +++ b/drivers/sensors/gnss_uorb.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -715,7 +716,7 @@ int gnss_register(FAR struct gnss_lowerhalf_s *lower, int devno, { FAR struct gnss_upperhalf_s *upper; FAR struct gnss_sensor_s *dev; - char path[PATH_MAX]; + FAR char *path; int ret; upper = kmm_zalloc(sizeof(struct gnss_upperhalf_s)); @@ -724,6 +725,13 @@ int gnss_register(FAR struct gnss_lowerhalf_s *lower, int devno, return -ENOMEM; } + path = lib_get_pathbuffer(); + if (path == NULL) + { + kmm_free(upper); + return -ENOMEM; + } + lower->push_data = gnss_push_data; lower->push_event = gnss_push_event; lower->priv = upper; @@ -814,6 +822,7 @@ int gnss_register(FAR struct gnss_lowerhalf_s *lower, int devno, goto driver_err; } + lib_put_pathbuffer(path); return ret; driver_err: @@ -832,6 +841,7 @@ gnss_err: nxmutex_destroy(&upper->lock); nxmutex_destroy(&upper->bufferlock); nxsem_destroy(&upper->buffersem); + lib_put_pathbuffer(path); kmm_free(upper); return ret; } @@ -853,7 +863,13 @@ gnss_err: void gnss_unregister(FAR struct gnss_lowerhalf_s *lower, int devno) { FAR struct gnss_upperhalf_s *upper = lower->priv; - char path[PATH_MAX]; + FAR char *path; + + path = lib_get_pathbuffer(); + if (path == NULL) + { + return; + } sensor_unregister(&upper->dev[GNSS_IDX].lower, devno); sensor_unregister(&upper->dev[GNSS_SATELLITE_IDX].lower, devno); @@ -864,5 +880,6 @@ void gnss_unregister(FAR struct gnss_lowerhalf_s *lower, int devno) unregister_driver(path); nxsem_destroy(&upper->buffersem); circbuf_uninit(&upper->buffer); + lib_put_pathbuffer(path); kmm_free(upper); } diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index 2edfc4f5a0..0d2dee8c67 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -41,6 +41,7 @@ #include #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -1240,16 +1241,25 @@ void sensor_remap_vector_raw16(FAR const int16_t *in, FAR int16_t *out, int sensor_register(FAR struct sensor_lowerhalf_s *lower, int devno) { - char path[PATH_MAX]; + FAR char *path; + int ret; DEBUGASSERT(lower != NULL); + path = lib_get_pathbuffer(); + if (path == NULL) + { + return -ENOMEM; + } + snprintf(path, PATH_MAX, DEVNAME_FMT, g_sensor_meta[lower->type].name, lower->uncalibrated ? DEVNAME_UNCAL : "", devno); - return sensor_custom_register(lower, path, - g_sensor_meta[lower->type].esize); + ret = sensor_custom_register(lower, path, + g_sensor_meta[lower->type].esize); + lib_put_pathbuffer(path); + return ret; } /**************************************************************************** @@ -1381,13 +1391,20 @@ rpmsg_err: void sensor_unregister(FAR struct sensor_lowerhalf_s *lower, int devno) { - char path[PATH_MAX]; + FAR char *path; + + path = lib_get_pathbuffer(); + if (path == NULL) + { + return; + } snprintf(path, PATH_MAX, DEVNAME_FMT, g_sensor_meta[lower->type].name, lower->uncalibrated ? DEVNAME_UNCAL : "", devno); sensor_custom_unregister(lower, path); + lib_put_pathbuffer(path); } /**************************************************************************** diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index 6e4a45a58c..e3d7b60ceb 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -44,6 +44,7 @@ #include #include #include +#include #ifdef CONFIG_FDSAN # include @@ -383,6 +384,7 @@ void files_initlist(FAR struct filelist *list) #ifdef CONFIG_SCHED_DUMP_ON_EXIT void files_dumplist(FAR struct filelist *list) { + FAR char *path; int count = files_countlist(list); int i; @@ -394,10 +396,15 @@ void files_dumplist(FAR struct filelist *list) "PID", "FD", "FLAGS", "TYPE", "POS", "PATH" ); + path = lib_get_pathbuffer(); + if (path == NULL) + { + return; + } + for (i = 0; i < count; i++) { FAR struct file *filep = files_fget(list, i); - char path[PATH_MAX]; #if CONFIG_FS_BACKTRACE > 0 char buf[BACKTRACE_BUFFER_SIZE(CONFIG_FS_BACKTRACE)]; @@ -433,6 +440,8 @@ void files_dumplist(FAR struct filelist *list) ); fs_putfilep(filep); } + + lib_put_pathbuffer(path); } #endif diff --git a/fs/mount/fs_automount.c b/fs/mount/fs_automount.c index cdcd510e3d..47fd173206 100644 --- a/fs/mount/fs_automount.c +++ b/fs/mount/fs_automount.c @@ -41,6 +41,7 @@ #include #include #include +#include #ifdef CONFIG_FS_AUTOMOUNTER_DRIVER # include @@ -809,7 +810,11 @@ FAR void *automount_initialize(FAR const struct automount_lower_s *lower) FAR struct automounter_state_s *priv; int ret; #ifdef CONFIG_FS_AUTOMOUNTER_DRIVER - char devpath[PATH_MAX]; + FAR char *devpath = lib_get_pathbuffer(); + if (devpath == NULL) + { + return; + } #endif /* CONFIG_FS_AUTOMOUNTER_DRIVER */ finfo("lower=%p\n", lower); @@ -853,10 +858,11 @@ FAR void *automount_initialize(FAR const struct automount_lower_s *lower) /* Register driver */ - snprintf(devpath, sizeof(devpath), + snprintf(devpath, PATH_MAX, CONFIG_FS_AUTOMOUNTER_VFS_PATH "%s", lower->mountpoint); ret = register_driver(devpath, &g_automount_fops, 0444, priv); + lib_put_pathbuffer(devpath); if (ret < 0) { ferr("ERROR: Failed to register automount driver: %d\n", ret); @@ -913,12 +919,17 @@ void automount_uninitialize(FAR void *handle) #ifdef CONFIG_FS_AUTOMOUNTER_DRIVER if (priv->registered) { - char devpath[PATH_MAX]; + FAR char *devpath = lib_get_pathbuffer(); + if (devpath == NULL) + { + return; + } - snprintf(devpath, sizeof(devpath), + snprintf(devpath, PATH_MAX, CONFIG_FS_AUTOMOUNTER_VFS_PATH "%s", lower->mountpoint); unregister_driver(devpath); + lib_put_pathbuffer(devpath); } nxmutex_destroy(&priv->lock); diff --git a/fs/partition/fs_partition.c b/fs/partition/fs_partition.c index fec9126521..9bb6fab735 100644 --- a/fs/partition/fs_partition.c +++ b/fs/partition/fs_partition.c @@ -93,9 +93,15 @@ static void register_partition(FAR struct partition_s *part, FAR void *arg) { FAR struct partition_register_s *reg = arg; FAR struct partition_state_s *state = reg->state; - char path[PATH_MAX]; + FAR char *path; - snprintf(path, sizeof(path), "%s/%s", reg->dir, part->name); + path = lib_get_pathbuffer(); + if (path == NULL) + { + return; + } + + snprintf(path, PATH_MAX, "%s/%s", reg->dir, part->name); if (state->blk != NULL) { register_partition_with_inode(path, 0660, state->blk, @@ -108,6 +114,8 @@ static void register_partition(FAR struct partition_s *part, FAR void *arg) part->firstblock, part->nblocks); } #endif + + lib_put_pathbuffer(path); } } diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 72165ce2f2..47ddab09cf 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -59,6 +59,7 @@ #include #include #include +#include #include "fs_heap.h" @@ -1252,7 +1253,7 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile, { FAR struct task_group_s *group = tcb->group; FAR struct file *filep; - char path[PATH_MAX]; + FAR char *path; size_t remaining; size_t linesize; size_t copysize; @@ -1292,6 +1293,12 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile, return totalsize; } + path = lib_get_pathbuffer(); + if (path == NULL) + { + return totalsize; + } + /* Examine each open file descriptor */ for (i = 0; i < count; i++) @@ -1336,10 +1343,12 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile, if (totalsize >= buflen) { + lib_put_pathbuffer(path); return totalsize; } } + lib_put_pathbuffer(path); return totalsize; } diff --git a/fs/rpmsgfs/rpmsgfs.c b/fs/rpmsgfs/rpmsgfs.c index 3c4beb26f4..e3674dcb07 100644 --- a/fs/rpmsgfs/rpmsgfs.c +++ b/fs/rpmsgfs/rpmsgfs.c @@ -282,7 +282,7 @@ static int rpmsgfs_open(FAR struct file *filep, FAR const char *relpath, FAR struct inode *inode; FAR struct rpmsgfs_mountpt_s *fs; FAR struct rpmsgfs_ofile_s *hf; - char path[PATH_MAX]; + FAR char *path; int ret; /* Sanity checks */ @@ -298,11 +298,18 @@ static int rpmsgfs_open(FAR struct file *filep, FAR const char *relpath, DEBUGASSERT(fs != NULL); + path = lib_get_pathbuffer(); + if (path == NULL) + { + return -ENOMEM; + } + /* Take the lock */ ret = nxmutex_lock(&fs->fs_lock); if (ret < 0) { + lib_put_pathbuffer(path); return ret; } @@ -317,7 +324,7 @@ static int rpmsgfs_open(FAR struct file *filep, FAR const char *relpath, /* Append to the host's root directory */ - rpmsgfs_mkpath(fs, relpath, path, sizeof(path)); + rpmsgfs_mkpath(fs, relpath, path, PATH_MAX); /* Try to open the file in the host file system */ @@ -370,6 +377,7 @@ errout_with_buffer: errout_with_lock: nxmutex_unlock(&fs->fs_lock); + lib_put_pathbuffer(path); if (ret == -EINVAL) { ret = -EIO; @@ -867,7 +875,7 @@ static int rpmsgfs_opendir(FAR struct inode *mountpt, { FAR struct rpmsgfs_mountpt_s *fs; FAR struct rpmsgfs_dir_s *rdir; - char path[PATH_MAX]; + FAR char *path; int ret; /* Sanity checks */ @@ -883,6 +891,13 @@ static int rpmsgfs_opendir(FAR struct inode *mountpt, return -ENOMEM; } + path = lib_get_pathbuffer(); + if (path == NULL) + { + fs_heap_free(rdir); + return -ENOMEM; + } + /* Take the lock */ ret = nxmutex_lock(&fs->fs_lock); @@ -893,7 +908,7 @@ static int rpmsgfs_opendir(FAR struct inode *mountpt, /* Append to the host's root directory */ - rpmsgfs_mkpath(fs, relpath, path, sizeof(path)); + rpmsgfs_mkpath(fs, relpath, path, PATH_MAX); /* Call the host's opendir function */ @@ -906,12 +921,14 @@ static int rpmsgfs_opendir(FAR struct inode *mountpt, *dir = (FAR struct fs_dirent_s *)rdir; nxmutex_unlock(&fs->fs_lock); + lib_put_pathbuffer(path); return OK; errout_with_lock: nxmutex_unlock(&fs->fs_lock); errout_with_rdir: + lib_put_pathbuffer(path); fs_heap_free(rdir); return ret; } @@ -1244,7 +1261,7 @@ static int rpmsgfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) static int rpmsgfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) { FAR struct rpmsgfs_mountpt_s *fs; - char path[PATH_MAX]; + FAR char *path; int ret; /* Sanity checks */ @@ -1255,21 +1272,29 @@ static int rpmsgfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) fs = mountpt->i_private; + path = lib_get_pathbuffer(); + if (path == NULL) + { + return -ENOMEM; + } + ret = nxmutex_lock(&fs->fs_lock); if (ret < 0) { + lib_put_pathbuffer(path); return ret; } /* Append to the host's root directory */ - rpmsgfs_mkpath(fs, relpath, path, sizeof(path)); + rpmsgfs_mkpath(fs, relpath, path, PATH_MAX); /* Call the host fs to perform the unlink */ ret = rpmsgfs_client_unlink(fs->handle, path); nxmutex_unlock(&fs->fs_lock); + lib_put_pathbuffer(path); return ret; } @@ -1284,7 +1309,7 @@ static int rpmsgfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, mode_t mode) { FAR struct rpmsgfs_mountpt_s *fs; - char path[PATH_MAX]; + FAR char *path; int ret; /* Sanity checks */ @@ -1295,21 +1320,29 @@ static int rpmsgfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, fs = mountpt->i_private; + path = lib_get_pathbuffer(); + if (path == NULL) + { + return -ENOMEM; + } + ret = nxmutex_lock(&fs->fs_lock); if (ret < 0) { + lib_put_pathbuffer(path); return ret; } /* Append to the host's root directory */ - rpmsgfs_mkpath(fs, relpath, path, sizeof(path)); + rpmsgfs_mkpath(fs, relpath, path, PATH_MAX); /* Call the host FS to do the mkdir */ ret = rpmsgfs_client_mkdir(fs->handle, path, mode); nxmutex_unlock(&fs->fs_lock); + lib_put_pathbuffer(path); return ret; } @@ -1323,7 +1356,7 @@ static int rpmsgfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, int rpmsgfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) { FAR struct rpmsgfs_mountpt_s *fs; - char path[PATH_MAX]; + FAR char *path; int ret; /* Sanity checks */ @@ -1336,21 +1369,29 @@ int rpmsgfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) /* Take the lock */ + path = lib_get_pathbuffer(); + if (path == NULL) + { + return -ENOMEM; + } + ret = nxmutex_lock(&fs->fs_lock); if (ret < 0) { + lib_put_pathbuffer(path); return ret; } /* Append to the host's root directory */ - rpmsgfs_mkpath(fs, relpath, path, sizeof(path)); + rpmsgfs_mkpath(fs, relpath, path, PATH_MAX); /* Call the host FS to do the mkdir */ ret = rpmsgfs_client_rmdir(fs->handle, path); nxmutex_unlock(&fs->fs_lock); + lib_put_pathbuffer(path); return ret; } @@ -1365,10 +1406,23 @@ int rpmsgfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, FAR const char *newrelpath) { FAR struct rpmsgfs_mountpt_s *fs; - char oldpath[PATH_MAX]; - char newpath[PATH_MAX]; + FAR char *oldpath; + FAR char *newpath; int ret; + oldpath = lib_get_pathbuffer(); + if (oldpath == NULL) + { + return -ENOMEM; + } + + newpath = lib_get_pathbuffer(); + if (newpath == NULL) + { + lib_put_pathbuffer(oldpath); + return -ENOMEM; + } + /* Sanity checks */ DEBUGASSERT(mountpt && mountpt->i_private); @@ -1380,21 +1434,25 @@ int rpmsgfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, ret = nxmutex_lock(&fs->fs_lock); if (ret < 0) { + lib_put_pathbuffer(oldpath); + lib_put_pathbuffer(newpath); return ret; } /* Append to the host's root directory */ - strlcpy(oldpath, fs->fs_root, sizeof(oldpath)); - strlcat(oldpath, oldrelpath, sizeof(oldpath)); - strlcpy(newpath, fs->fs_root, sizeof(newpath)); - strlcat(newpath, newrelpath, sizeof(newpath)); + strlcpy(oldpath, fs->fs_root, PATH_MAX); + strlcat(oldpath, oldrelpath, PATH_MAX); + strlcpy(newpath, fs->fs_root, PATH_MAX); + strlcat(newpath, newrelpath, PATH_MAX); /* Call the host FS to do the mkdir */ ret = rpmsgfs_client_rename(fs->handle, oldpath, newpath); nxmutex_unlock(&fs->fs_lock); + lib_put_pathbuffer(oldpath); + lib_put_pathbuffer(newpath); return ret; } @@ -1409,7 +1467,7 @@ static int rpmsgfs_stat(FAR struct inode *mountpt, FAR const char *relpath, FAR struct stat *buf) { FAR struct rpmsgfs_mountpt_s *fs; - char path[PATH_MAX]; + FAR char *path; int ret; /* Sanity checks */ @@ -1420,21 +1478,29 @@ static int rpmsgfs_stat(FAR struct inode *mountpt, FAR const char *relpath, fs = mountpt->i_private; + path = lib_get_pathbuffer(); + if (path == NULL) + { + return -ENOMEM; + } + ret = nxmutex_lock(&fs->fs_lock); if (ret < 0) { + lib_put_pathbuffer(path); return ret; } /* Append to the host's root directory */ - rpmsgfs_mkpath(fs, relpath, path, sizeof(path)); + rpmsgfs_mkpath(fs, relpath, path, PATH_MAX); /* Call the host FS to do the stat operation */ ret = rpmsgfs_client_stat(fs->handle, path, buf); nxmutex_unlock(&fs->fs_lock); + lib_put_pathbuffer(path); return ret; } @@ -1449,7 +1515,7 @@ static int rpmsgfs_chstat(FAR struct inode *mountpt, FAR const char *relpath, FAR const struct stat *buf, int flags) { FAR struct rpmsgfs_mountpt_s *fs; - char path[PATH_MAX]; + FAR char *path; int ret; /* Sanity checks */ @@ -1460,20 +1526,28 @@ static int rpmsgfs_chstat(FAR struct inode *mountpt, FAR const char *relpath, fs = mountpt->i_private; + path = lib_get_pathbuffer(); + if (path == NULL) + { + return -ENOMEM; + } + ret = nxmutex_lock(&fs->fs_lock); if (ret < 0) { + lib_put_pathbuffer(path); return ret; } /* Append to the host's root directory */ - rpmsgfs_mkpath(fs, relpath, path, sizeof(path)); + rpmsgfs_mkpath(fs, relpath, path, PATH_MAX); /* Call the host FS to do the chstat operation */ ret = rpmsgfs_client_chstat(fs->handle, path, buf, flags); nxmutex_unlock(&fs->fs_lock); + lib_put_pathbuffer(path); return ret; } diff --git a/fs/v9fs/client.c b/fs/v9fs/client.c index c20c4442a3..e113ed39e4 100644 --- a/fs/v9fs/client.c +++ b/fs/v9fs/client.c @@ -1603,12 +1603,8 @@ int v9fs_client_init(FAR struct v9fs_client_s *client, FAR const char *data) { FAR const char *options; + FAR char *aname; char transport[NAME_MAX]; - char aname[PATH_MAX] = - { - 0 - }; - char uname[NAME_MAX] = { 0 @@ -1617,6 +1613,14 @@ int v9fs_client_init(FAR struct v9fs_client_s *client, size_t length; int ret; + aname = lib_get_pathbuffer(); + if (aname == NULL) + { + return -ENOMEM; + } + + aname[0] = '\0'; + /* Parse commandline */ options = data; @@ -1657,6 +1661,7 @@ int v9fs_client_init(FAR struct v9fs_client_s *client, ret = v9fs_transport_create(&client->transport, transport, data); if (ret < 0) { + lib_put_pathbuffer(aname); return ret; } @@ -1664,6 +1669,7 @@ int v9fs_client_init(FAR struct v9fs_client_s *client, if (client->fids == NULL) { v9fs_transport_destroy(client->transport); + lib_put_pathbuffer(aname); return -ENOMEM; } @@ -1687,12 +1693,14 @@ int v9fs_client_init(FAR struct v9fs_client_s *client, client->root_fid = ret; client->tag_id = 1; + lib_put_pathbuffer(aname); return 0; out: v9fs_transport_destroy(client->transport); nxmutex_destroy(&client->lock); idr_destroy(client->fids); + lib_put_pathbuffer(aname); return ret; } diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c index d67ab6d588..585df77e14 100644 --- a/fs/vfs/fs_dir.c +++ b/fs/vfs/fs_dir.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "inode/inode.h" #include "fs_heap.h" @@ -583,9 +584,15 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) { FAR struct fs_dirent_s *dir; FAR struct inode *inode = filep->f_inode; - char path_prefix[PATH_MAX]; + FAR char *path_prefix; int ret; + path_prefix = lib_get_pathbuffer(); + if (path_prefix == NULL) + { + return -ENOMEM; + } + /* Is this a node in the pseudo filesystem? Or a mountpoint? */ #ifndef CONFIG_DISABLE_MOUNTPOINT @@ -596,6 +603,7 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) ret = open_mountpoint(inode, relpath, &dir); if (ret < 0) { + lib_put_pathbuffer(path_prefix); return ret; } } @@ -605,20 +613,23 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) ret = open_pseudodir(inode, &dir); if (ret < 0) { + lib_put_pathbuffer(path_prefix); return ret; } } - inode_getpath(inode, path_prefix, sizeof(path_prefix)); + inode_getpath(inode, path_prefix, PATH_MAX); ret = fs_heap_asprintf(&dir->fd_path, "%s%s/", path_prefix, relpath); if (ret < 0) { dir->fd_path = NULL; + lib_put_pathbuffer(path_prefix); return ret; } filep->f_inode = &g_dir_inode; filep->f_priv = dir; inode_addref(&g_dir_inode); + lib_put_pathbuffer(path_prefix); return ret; } diff --git a/libs/libc/locale/lib_catalog.c b/libs/libc/locale/lib_catalog.c index 06944e940b..6a783e3189 100644 --- a/libs/libc/locale/lib_catalog.c +++ b/libs/libc/locale/lib_catalog.c @@ -177,6 +177,7 @@ nl_catd catopen(FAR const char *name, int oflag) FAR const char *lang; FAR const char *p; FAR const char *z; + FAR char *buf; if (strchr(name, '/')) { @@ -195,9 +196,15 @@ nl_catd catopen(FAR const char *name, int oflag) lang = ""; } + buf = lib_get_pathbuffer(); + if (buf == NULL) + { + set_errno(ENOMEM); + return MAP_FAILED; + } + for (p = path; *p; p = z) { - char buf[PATH_MAX]; nl_catd catd; size_t i; @@ -261,7 +268,7 @@ nl_catd catopen(FAR const char *name, int oflag) l = 1; } - if (v == NULL || i + l >= sizeof(buf)) + if (v == NULL || i + l >= PATH_MAX) { break; } @@ -286,10 +293,12 @@ nl_catd catopen(FAR const char *name, int oflag) catd = catmap(i ? buf : name); if (catd != MAP_FAILED) { + lib_put_pathbuffer(buf); return catd; } } + lib_put_pathbuffer(buf); set_errno(ENOENT); return MAP_FAILED; } diff --git a/libs/libc/locale/lib_gettext.c b/libs/libc/locale/lib_gettext.c index 5a86302510..12aa367aad 100644 --- a/libs/libc/locale/lib_gettext.c +++ b/libs/libc/locale/lib_gettext.c @@ -549,9 +549,9 @@ FAR char *dcngettext(FAR const char *domainname, { FAR struct mofile_s *mofile; FAR const char *lang; - char path[PATH_MAX]; FAR char *notrans; FAR char *trans; + FAR char *path; notrans = (FAR char *)(n == 1 ? msgid1 : msgid2); @@ -576,6 +576,12 @@ FAR char *dcngettext(FAR const char *domainname, lang = "C"; } + path = lib_get_pathbuffer(); + if (path == NULL) + { + return notrans; + } + snprintf(path, PATH_MAX, CONFIG_LIBC_LOCALE_PATH"/%s/%s/%s.mo", lang, g_catname[category], domainname); @@ -598,6 +604,7 @@ FAR char *dcngettext(FAR const char *domainname, if (mofile == NULL) { nxmutex_unlock(&g_lock); + lib_put_pathbuffer(path); return notrans; } @@ -606,6 +613,7 @@ FAR char *dcngettext(FAR const char *domainname, if (mofile->map == MAP_FAILED) { nxmutex_unlock(&g_lock); + lib_put_pathbuffer(path); lib_free(mofile); return notrans; } @@ -651,6 +659,7 @@ FAR char *dcngettext(FAR const char *domainname, } nxmutex_unlock(&g_lock); /* Leave look before search */ + lib_put_pathbuffer(path); trans = molookup(mofile->map, mofile->size, msgid1); if (trans == NULL) diff --git a/libs/libc/misc/lib_fchmodat.c b/libs/libc/misc/lib_fchmodat.c index 65186a39b0..5083bdb19a 100644 --- a/libs/libc/misc/lib_fchmodat.c +++ b/libs/libc/misc/lib_fchmodat.c @@ -66,20 +66,33 @@ int fchmodat(int dirfd, FAR const char *path, mode_t mode, int flags) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } if ((flags & AT_SYMLINK_NOFOLLOW) != 0) { - return lchmod(fullpath, mode); + ret = lchmod(fullpath, mode); + } + else + { + ret = chmod(fullpath, mode); } - return chmod(fullpath, mode); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/misc/lib_fstatat.c b/libs/libc/misc/lib_fstatat.c index f9660719d8..4a1ded9773 100644 --- a/libs/libc/misc/lib_fstatat.c +++ b/libs/libc/misc/lib_fstatat.c @@ -67,20 +67,33 @@ int fstatat(int dirfd, FAR const char *path, FAR struct stat *buf, int flags) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } if ((flags & AT_SYMLINK_NOFOLLOW) != 0) { - return lstat(fullpath, buf); + ret = lstat(fullpath, buf); + } + else + { + ret = stat(fullpath, buf); } - return stat(fullpath, buf); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/misc/lib_ftok.c b/libs/libc/misc/lib_ftok.c index 20022ea2a3..ed35966a29 100644 --- a/libs/libc/misc/lib_ftok.c +++ b/libs/libc/misc/lib_ftok.c @@ -31,6 +31,7 @@ #include #include #include +#include /**************************************************************************** * Public Functions @@ -60,9 +61,17 @@ key_t ftok(FAR const char *pathname, int proj_id) { - char fullpath[PATH_MAX] = CONFIG_LIBC_FTOK_VFS_PATH "/"; + FAR char *fullpath; struct stat st; + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + return (key_t)-1; + } + + snprintf(fullpath, PATH_MAX, "%s/", + CONFIG_LIBC_FTOK_VFS_PATH); strlcat(fullpath, pathname, sizeof(fullpath)); if (stat(fullpath, &st) < 0 && get_errno() == ENOENT) { @@ -71,10 +80,12 @@ key_t ftok(FAR const char *pathname, int proj_id) if (mkdir(fullpath, S_IRWXU) < 0 || stat(fullpath, &st) < 0) { + lib_put_pathbuffer(fullpath); return (key_t)-1; } } + lib_put_pathbuffer(fullpath); return ((key_t)proj_id << 24 | (key_t)(st.st_dev & 0xff) << 16 | (key_t)(st.st_ino & 0xffff)); diff --git a/libs/libc/misc/lib_glob.c b/libs/libc/misc/lib_glob.c index e86811bd17..40c4562464 100644 --- a/libs/libc/misc/lib_glob.c +++ b/libs/libc/misc/lib_glob.c @@ -417,11 +417,17 @@ int glob(FAR const char *pat, int flags, size_t i; size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0; int error = 0; - char buf[PATH_MAX]; + FAR char *buf; head.next = NULL; head.name[0] = '\0'; + buf = lib_get_pathbuffer(); + if (buf == NULL) + { + return -ENOMEM; + } + if (!errfunc) { errfunc = ignore_err; @@ -442,6 +448,7 @@ int glob(FAR const char *pat, int flags, if (!p) { + lib_put_pathbuffer(buf); return GLOB_NOSPACE; } @@ -453,6 +460,7 @@ int glob(FAR const char *pat, int flags, lib_free(p); } + lib_put_pathbuffer(buf); if (error == GLOB_NOSPACE) { freelist(&head); diff --git a/libs/libc/misc/lib_memfd.c b/libs/libc/misc/lib_memfd.c index 58d1dac1d4..9b45d2a22e 100644 --- a/libs/libc/misc/lib_memfd.c +++ b/libs/libc/misc/lib_memfd.c @@ -30,6 +30,7 @@ #include #include #include +#include #if defined(CONFIG_LIBC_MEMFD_TMPFS) || defined(CONFIG_LIBC_MEMFD_SHMFS) /**************************************************************************** @@ -54,10 +55,17 @@ int memfd_create(FAR const char *name, unsigned int flags) set_errno(ENOSYS); return -1; #else - char path[PATH_MAX]; + FAR char *path; int ret; - snprintf(path, sizeof(path), LIBC_MEM_FD_VFS_PATH_FMT, name); + path = lib_get_pathbuffer(); + if (path == NULL) + { + set_errno(ENOMEM); + return -1; + } + + snprintf(path, PATH_MAX, LIBC_MEM_FD_VFS_PATH_FMT, name); # ifdef CONFIG_LIBC_MEMFD_SHMFS ret = shm_open(path, O_RDWR | flags, 0660); if (ret >= 0) @@ -73,6 +81,7 @@ int memfd_create(FAR const char *name, unsigned int flags) } # endif + lib_put_pathbuffer(path); return ret; #endif } diff --git a/libs/libc/misc/lib_mkdirat.c b/libs/libc/misc/lib_mkdirat.c index df306096d3..afd33c2daa 100644 --- a/libs/libc/misc/lib_mkdirat.c +++ b/libs/libc/misc/lib_mkdirat.c @@ -64,15 +64,25 @@ int mkdirat(int dirfd, FAR const char *path, mode_t mode) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } - return mkdir(fullpath, mode); + ret = mkdir(fullpath, mode); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/misc/lib_mkfifo.c b/libs/libc/misc/lib_mkfifo.c index 407f08ae64..bf0c907f2a 100644 --- a/libs/libc/misc/lib_mkfifo.c +++ b/libs/libc/misc/lib_mkfifo.c @@ -114,17 +114,27 @@ int mkfifo(FAR const char *pathname, mode_t mode) int mkfifoat(int dirfd, FAR const char *path, mode_t mode) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } - return mkfifo(fullpath, mode); + ret = mkfifo(fullpath, mode); + lib_put_pathbuffer(fullpath); + return ret; } #endif /* CONFIG_PIPES && CONFIG_DEV_FIFO_SIZE > 0 */ diff --git a/libs/libc/misc/lib_mknod.c b/libs/libc/misc/lib_mknod.c index afb70a6c77..b01cfe1001 100644 --- a/libs/libc/misc/lib_mknod.c +++ b/libs/libc/misc/lib_mknod.c @@ -134,15 +134,25 @@ int mknod(FAR const char *path, mode_t mode, dev_t dev) int mknodat(int dirfd, FAR const char *path, mode_t mode, dev_t dev) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } - return mknod(fullpath, mode, dev); + ret = mknod(fullpath, mode, dev); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/misc/lib_openat.c b/libs/libc/misc/lib_openat.c index 9c35df7fc5..b49ad9d958 100644 --- a/libs/libc/misc/lib_openat.c +++ b/libs/libc/misc/lib_openat.c @@ -65,13 +65,21 @@ int openat(int dirfd, FAR const char *path, int oflags, ...) { - char fullpath[PATH_MAX]; + FAR char *fullpath; mode_t mode = 0; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } @@ -85,5 +93,7 @@ int openat(int dirfd, FAR const char *path, int oflags, ...) va_end(ap); } - return open(fullpath, oflags, mode); + ret = open(fullpath, oflags, mode); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/misc/lib_utimensat.c b/libs/libc/misc/lib_utimensat.c index 4c16ace456..cf0353fd7f 100644 --- a/libs/libc/misc/lib_utimensat.c +++ b/libs/libc/misc/lib_utimensat.c @@ -66,20 +66,33 @@ int utimensat(int dirfd, FAR const char *path, const struct timespec times[2], int flags) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } if ((flags & AT_SYMLINK_NOFOLLOW) != 0) { - return lutimens(fullpath, times); + ret = lutimens(fullpath, times); + } + else + { + ret = utimens(fullpath, times); } - return utimens(fullpath, times); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/stdio/lib_renameat.c b/libs/libc/stdio/lib_renameat.c index f1e3319cf3..84d4b13578 100644 --- a/libs/libc/stdio/lib_renameat.c +++ b/libs/libc/stdio/lib_renameat.c @@ -70,23 +70,43 @@ int renameat(int olddirfd, FAR const char *oldpath, int newdirfd, FAR const char *newpath) { - char oldfullpath[PATH_MAX]; - char newfullpath[PATH_MAX]; + FAR char *oldfullpath; + FAR char *newfullpath; int ret; + oldfullpath = lib_get_pathbuffer(); + if (oldfullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + newfullpath = lib_get_pathbuffer(); + if (newfullpath == NULL) + { + lib_put_pathbuffer(oldfullpath); + set_errno(ENOMEM); + return ERROR; + } + ret = lib_getfullpath(olddirfd, oldpath, - oldfullpath, sizeof(oldfullpath)); + oldfullpath, PATH_MAX); if (ret >= 0) { ret = lib_getfullpath(newdirfd, newpath, - newfullpath, sizeof(newfullpath)); + newfullpath, PATH_MAX); } if (ret < 0) { + lib_put_pathbuffer(oldfullpath); + lib_put_pathbuffer(newfullpath); set_errno(-ret); return ERROR; } - return rename(oldfullpath, newfullpath); + ret = rename(oldfullpath, newfullpath); + lib_put_pathbuffer(oldfullpath); + lib_put_pathbuffer(newfullpath); + return ret; } diff --git a/libs/libc/unistd/lib_access.c b/libs/libc/unistd/lib_access.c index 9ad7e421d0..9e76621e73 100644 --- a/libs/libc/unistd/lib_access.c +++ b/libs/libc/unistd/lib_access.c @@ -137,15 +137,25 @@ int access(FAR const char *path, int amode) int faccessat(int dirfd, FAR const char *path, int amode, int flags) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } - return access(fullpath, amode); + ret = access(fullpath, amode); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/unistd/lib_fchdir.c b/libs/libc/unistd/lib_fchdir.c index 19e0794f1f..06cd1aaa74 100644 --- a/libs/libc/unistd/lib_fchdir.c +++ b/libs/libc/unistd/lib_fchdir.c @@ -26,9 +26,11 @@ #include +#include #include #include #include +#include #ifndef CONFIG_DISABLE_ENVIRON @@ -66,16 +68,26 @@ int fchdir(int fd) { - char path[PATH_MAX]; + FAR char *path; int ret; + path = lib_get_pathbuffer(); + if (path == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + ret = fcntl(fd, F_GETPATH, path); if (ret < 0) { + lib_put_pathbuffer(path); return ret; } - return chdir(path); + ret = chdir(path); + lib_put_pathbuffer(path); + return ret; } #endif /* !CONFIG_DISABLE_ENVIRON */ diff --git a/libs/libc/unistd/lib_fchownat.c b/libs/libc/unistd/lib_fchownat.c index 8992f65e20..75b62d85e7 100644 --- a/libs/libc/unistd/lib_fchownat.c +++ b/libs/libc/unistd/lib_fchownat.c @@ -68,20 +68,33 @@ int fchownat(int dirfd, FAR const char *path, uid_t owner, gid_t group, int flags) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } if ((flags & AT_SYMLINK_NOFOLLOW) != 0) { - return lchown(fullpath, owner, group); + ret = lchown(fullpath, owner, group); + } + else + { + ret = chown(fullpath, owner, group); } - return chown(fullpath, owner, group); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/unistd/lib_linkat.c b/libs/libc/unistd/lib_linkat.c index cb0729a2c7..1448f2a756 100644 --- a/libs/libc/unistd/lib_linkat.c +++ b/libs/libc/unistd/lib_linkat.c @@ -78,25 +78,45 @@ int linkat(int olddirfd, FAR const char *path1, int newdirfd, FAR const char *path2, int flags) { - char oldfullpath[PATH_MAX]; - char newfullpath[PATH_MAX]; + FAR char *oldfullpath; + FAR char *newfullpath; int ret; + oldfullpath = lib_get_pathbuffer(); + if (oldfullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + newfullpath = lib_get_pathbuffer(); + if (newfullpath == NULL) + { + lib_put_pathbuffer(oldfullpath); + set_errno(ENOMEM); + return ERROR; + } + ret = lib_getfullpath(olddirfd, path1, - oldfullpath, sizeof(oldfullpath)); + oldfullpath, PATH_MAX); if (ret >= 0) { ret = lib_getfullpath(newdirfd, path2, - newfullpath, sizeof(newfullpath)); + newfullpath, PATH_MAX); } if (ret < 0) { + lib_put_pathbuffer(oldfullpath); + lib_put_pathbuffer(newfullpath); set_errno(-ret); return ERROR; } - return link(oldfullpath, newfullpath); + ret = link(oldfullpath, newfullpath); + lib_put_pathbuffer(oldfullpath); + lib_put_pathbuffer(newfullpath); + return ret; } #endif /* CONFIG_PSEUDOFS_SOFTLINKS */ diff --git a/libs/libc/unistd/lib_readlinkat.c b/libs/libc/unistd/lib_readlinkat.c index 8d3043b9a7..3fa2e8705a 100644 --- a/libs/libc/unistd/lib_readlinkat.c +++ b/libs/libc/unistd/lib_readlinkat.c @@ -70,17 +70,27 @@ ssize_t readlinkat(int dirfd, FAR const char *path, FAR char *buf, size_t bufsize) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } - return readlink(fullpath, buf, bufsize); + ret = readlink(fullpath, buf, bufsize); + lib_put_pathbuffer(fullpath); + return ret; } #endif /* CONFIG_PSEUDOFS_SOFTLINKS */ diff --git a/libs/libc/unistd/lib_symlinkat.c b/libs/libc/unistd/lib_symlinkat.c index 14ebe44a85..6063839ebc 100644 --- a/libs/libc/unistd/lib_symlinkat.c +++ b/libs/libc/unistd/lib_symlinkat.c @@ -67,17 +67,27 @@ int symlinkat(FAR const char *path1, int dirfd, FAR const char *path2) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path2, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path2, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } - return symlink(path1, fullpath); + ret = symlink(path1, fullpath); + lib_put_pathbuffer(fullpath); + return ret; } #endif /* CONFIG_PSEUDOFS_SOFTLINKS */ diff --git a/libs/libc/unistd/lib_unlinkat.c b/libs/libc/unistd/lib_unlinkat.c index a63acb54e6..b3d5087bdd 100644 --- a/libs/libc/unistd/lib_unlinkat.c +++ b/libs/libc/unistd/lib_unlinkat.c @@ -68,20 +68,33 @@ int unlinkat(int dirfd, FAR const char *path, int flags) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } if ((flags & AT_REMOVEDIR) != 0) { - return rmdir(fullpath); + ret = rmdir(fullpath); + } + else + { + ret = unlink(fullpath); } - return unlink(fullpath); + lib_put_pathbuffer(fullpath); + return ret; } diff --git a/libs/libc/unistd/lib_utimes.c b/libs/libc/unistd/lib_utimes.c index 4ed8da56a4..659d3ac9f6 100644 --- a/libs/libc/unistd/lib_utimes.c +++ b/libs/libc/unistd/lib_utimes.c @@ -53,15 +53,25 @@ int utimes(FAR const char *path, const struct timeval tv[2]) int futimesat(int dirfd, FAR const char *path, const struct timeval tv[2]) { - char fullpath[PATH_MAX]; + FAR char *fullpath; int ret; - ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); + fullpath = lib_get_pathbuffer(); + if (fullpath == NULL) + { + set_errno(ENOMEM); + return ERROR; + } + + ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX); if (ret < 0) { + lib_put_pathbuffer(fullpath); set_errno(-ret); return ERROR; } - return utimes(fullpath, tv); + ret = utimes(fullpath, tv); + lib_put_pathbuffer(fullpath); + return ret; }