util/nvmutil: more secure tmpdir()

use stat instead of access (race conditions)

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-16 16:19:27 +00:00
parent 1ce06b01e0
commit 26d8807b79
+7 -4
View File
@@ -3088,15 +3088,18 @@ static char *
x_c_tmpdir(void)
{
char *t;
struct stat st;
t = getenv("TMPDIR");
if (t && *t)
return t;
if (t && *t) {
if (stat(t, &st) == 0 && S_ISDIR(st.st_mode))
return t;
}
if (access("/tmp", W_OK) == 0)
if (stat("/tmp", &st) == 0 && S_ISDIR(st.st_mode))
return "/tmp";
if (access("/var/tmp", W_OK) == 0)
if (stat("/var/tmp", &st) == 0 && S_ISDIR(st.st_mode))
return "/var/tmp";
return ".";