mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-20 23:15:14 +02:00
util/nvmutil: more secure mkstemp
try a few more times until success explicitly return EEXIST when needed we try multiple times and check more thoroughly if a file exists, thus reducing the risk of race conditions Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -3009,14 +3009,21 @@ static int
|
|||||||
x_i_mkstemp(char *template)
|
x_i_mkstemp(char *template)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
if (mktemp(template) == NULL)
|
if (mktemp(template) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
|
fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||||
|
if (fd >= 0)
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errno = EEXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
x_c_strrchr(const char *s, int c)
|
x_c_strrchr(const char *s, int c)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user