mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
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:
@@ -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 ".";
|
||||
|
||||
Reference in New Issue
Block a user