From df99f345dc410fdfdaeee5b4c1078f7544c31886 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 22 Mar 2026 20:06:10 +0000 Subject: WIP cleanup Signed-off-by: Leah Rowe --- util/nvmutil/lib/file.c | 51 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 41 deletions(-) (limited to 'util/nvmutil/lib') 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; } -- cgit v1.2.1