mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-20 15:03:44 +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)
|
x_c_tmpdir(void)
|
||||||
{
|
{
|
||||||
char *t;
|
char *t;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
t = getenv("TMPDIR");
|
t = getenv("TMPDIR");
|
||||||
if (t && *t)
|
if (t && *t) {
|
||||||
return 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";
|
return "/tmp";
|
||||||
|
|
||||||
if (access("/var/tmp", W_OK) == 0)
|
if (stat("/var/tmp", &st) == 0 && S_ISDIR(st.st_mode))
|
||||||
return "/var/tmp";
|
return "/var/tmp";
|
||||||
|
|
||||||
return ".";
|
return ".";
|
||||||
|
|||||||
Reference in New Issue
Block a user