diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-24 02:41:26 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-24 02:41:53 +0000 |
| commit | 2c21a04741eed260570c7ed3ded08c639e65a689 (patch) | |
| tree | 7f27330a1d7a59f875a4179b7a4d754d5a7da9b2 /util/libreboot-utils/lib | |
| parent | a5eed39a76e257e4a257ddce89a1bff3618fc12a (diff) | |
util/mkhtemp: show path on error accessing it
a bit naughty the way i do it, but it works. without
this, the message gets clobbered by EINVAL due to
a bad call to vprintf in the err function.
in this way, we ensure that there is a path, and
thus the errno does not get clobbered. i also
removed the EPERM setting in the env_tmpdir
function, which also clobbered errno.
with this fix, if TMPDIR is set but invalid,
it should now show the error reliably.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils/lib')
| -rw-r--r-- | util/libreboot-utils/lib/mkhtemp.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c index 8d58dcc5..e1ca0a10 100644 --- a/util/libreboot-utils/lib/mkhtemp.c +++ b/util/libreboot-utils/lib/mkhtemp.c @@ -63,6 +63,8 @@ new_tmp_common(int *fd, char **path, int type) struct stat st_dir_initial; + char *fail_dir = NULL; + if (path == NULL || fd == NULL) { errno = EFAULT; goto err; @@ -89,9 +91,9 @@ new_tmp_common(int *fd, char **path, int type) #if defined(PERMIT_NON_STICKY_ALWAYS) && \ ((PERMIT_NON_STICKY_ALWAYS) > 0) - tmpdir = env_tmpdir(PERMIT_NON_STICKY_ALWAYS); + tmpdir = env_tmpdir(PERMIT_NON_STICKY_ALWAYS, &fail_dir); #else - tmpdir = env_tmpdir(0); + tmpdir = env_tmpdir(0, &fail_dir); #endif if (tmpdir == NULL) goto err; @@ -176,6 +178,13 @@ err: *fd = -1; } + /* where a TMPDIR isn't found, and we err, + * we pass this back through for the + * error message + */ + if (fail_dir != NULL) + *path = fail_dir; + errno = saved_errno; return -1; } @@ -185,26 +194,31 @@ err: */ char * -env_tmpdir(int bypass_all_sticky_checks) +env_tmpdir(int bypass_all_sticky_checks, char **tmpdir) { char *t; int allow_noworld_unsticky; int saved_errno = errno; + char tmp[] = "/tmp"; + char vartmp[] = "/var/tmp"; + t = getenv("TMPDIR"); if (t != NULL && *t != '\0') { if (tmpdir_policy(t, &allow_noworld_unsticky) < 0) { - errno = EPERM; + if (tmpdir != NULL) + *tmpdir = t; return NULL; /* errno already set */ } if (!world_writeable_and_sticky(t, allow_noworld_unsticky, bypass_all_sticky_checks)) { - errno = EPERM; + if (tmpdir != NULL) + *tmpdir = t; return NULL; } @@ -218,6 +232,9 @@ env_tmpdir(int bypass_all_sticky_checks) allow_noworld_unsticky, bypass_all_sticky_checks)) { + if (tmpdir != NULL) + *tmpdir = tmp; + errno = saved_errno; return "/tmp"; } @@ -226,13 +243,13 @@ env_tmpdir(int bypass_all_sticky_checks) allow_noworld_unsticky, bypass_all_sticky_checks)) { + if (tmpdir != NULL) + *tmpdir = vartmp; + errno = saved_errno; return "/var/tmp"; } - if (errno == saved_errno) - errno = EPERM; - return NULL; } |
