summaryrefslogtreecommitdiff
path: root/util/nvmutil/lib/file.c
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-22 20:06:10 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-22 20:06:10 +0000
commitdf99f345dc410fdfdaeee5b4c1078f7544c31886 (patch)
tree88cc627f445fe812673f993402316f05ab6ee374 /util/nvmutil/lib/file.c
parenta505cb261a22194c9c7f4f1a3426d3ce45a3bdf2 (diff)
WIP cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/lib/file.c')
-rw-r--r--util/nvmutil/lib/file.c51
1 files changed, 10 insertions, 41 deletions
diff --git a/util/nvmutil/lib/file.c b/util/nvmutil/lib/file.c
index f6519c85..8ebb93d7 100644
--- a/util/nvmutil/lib/file.c
+++ b/util/nvmutil/lib/file.c
@@ -711,13 +711,10 @@ int mkhtemp(int *fd,
* only supports *files*.
* it doesn't make tmp*dirs*
*/
-
size_t len = 0;
char *p = NULL;
char *template_copy = NULL;
-
size_t xc = 0;
-
size_t r;
#if defined(PATH_LEN) && \
(PATH_LEN) >= 256
@@ -725,29 +722,17 @@ int mkhtemp(int *fd,
#else
size_t max_len = 4096;
#endif
-
int file_created = 0;
-
int saved_errno = errno;
struct stat st_tmp;
-
mode_t old_umask;
-
char *fname_copy = NULL;
size_t fname_len = 0;
-
/* for ctrl char check
*/
unsigned char ctrl = 0;
size_t ctrl_pos = 0;
-
- /* in openat mode, we re-check
- directory against previous
- check done by the caller,
- * mitigating symlink attacks
- */
struct stat st_dir_now;
-
size_t retries = 0;
#if !(defined(MAX_MKHTEMP_RETRIES) && \
(MAX_MKHTEMP_RETRIES) >= 128)
@@ -756,46 +741,27 @@ int mkhtemp(int *fd,
size_t max_retries = 128;
#endif
-
if (fname == NULL ||
- st_dir_initial == NULL) {
+ st_dir_initial == NULL ||
+ fd == NULL) {
errno = EFAULT;
goto err_mkhtemp;
}
-
- if (slen(fname, max_len, &fname_len) < 0)
- goto err_mkhtemp;
-
- if (fname_len == 0) {
- errno = EINVAL;
- goto err_mkhtemp;
- }
-
if (dirfd < 0) {
errno = EBADF;
goto err_mkhtemp;
}
-
- if (fd == NULL ||
- template == NULL) {
-
- errno = EFAULT;
- goto err_mkhtemp;
- }
-
if (*fd >= 0) {
errno = EEXIST;
goto err_mkhtemp;
}
- if (slen(template, max_len, &len) < 0)
+ if (slen(template, max_len, &len) < 0) {
goto err_mkhtemp;
-
- /* bounds check */
- if (len >= max_len) {
+ } else if (len >= max_len) { /* bounds check */
errno = EMSGSIZE;
goto err_mkhtemp;
}
@@ -813,10 +779,14 @@ int mkhtemp(int *fd,
/* reject dangerous basenames
*/
- if (fname[0] == '\0' ||
+ if (slen(fname, max_len, &fname_len) < 0) {
+ goto err_mkhtemp;
+ } else if (fname_len == 0) {
+ errno = EINVAL;
+ goto err_mkhtemp;
+ } else if (fname[0] == '\0' ||
(fname[0] == '.' && fname[1] == '\0') ||
(fname[0] == '.' && fname[1] == '.' && fname[2] == '\0')) {
-
errno = EINVAL;
goto err_mkhtemp;
}
@@ -829,7 +799,6 @@ int mkhtemp(int *fd,
ctrl = (unsigned char)fname[ctrl_pos];
if (ctrl < 32 || ctrl == 127) {
-
errno = EINVAL;
goto err_mkhtemp;
}