diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-04-02 22:11:50 +0100 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-04-10 22:59:08 +0100 |
| commit | fc3c7b9c3eeaa156ef235e172309e27bc7f2707b (patch) | |
| tree | 64e166812a61b0708d491a08b5df0bed6fd53465 | |
| parent | 7eecc42b92f43c72f950f9840e86d298ed83bf8f (diff) | |
lbutils/file: tidy up mkhtemp_tmpfile_linux
make failure more obvious. no behavioural change.
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/libreboot-utils/lib/mkhtemp.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c index bb714b82..4d511892 100644 --- a/util/libreboot-utils/lib/mkhtemp.c +++ b/util/libreboot-utils/lib/mkhtemp.c @@ -694,26 +694,27 @@ mkhtemp_tmpfile_linux(int dirfd, st_dir_first) < 0) goto err; - if (linkat(tmpfd, "", dirfd, fname_copy, AT_EMPTY_PATH) == 0) { + if (linkat(tmpfd, "", dirfd, + fname_copy, AT_EMPTY_PATH) == -1) { - linked = 1; /* file created */ - - /* TODO: potential fd leak here. - * probably should only set *fd on successful - * return from this function (see below) - */ - if (fd_verify_dir_identity(dirfd, st_dir_first) < 0 || - fstat(*fd = tmpfd, st) < 0 || - secure_file(fd, st, st, O_APPEND, 1, 1, 0600) < 0) + if (errno == EEXIST) + continue; /* retry on collision */ + else goto err; - - goto out; } - if (errno != EEXIST) + linked = 1; /* file created */ + + /* TODO: potential fd leak here. + * probably should only set *fd on successful + * return from this function (see below) + */ + if (fd_verify_dir_identity(dirfd, st_dir_first) < 0 || + fstat(*fd = tmpfd, st) < 0 || + secure_file(fd, st, st, O_APPEND, 1, 1, 0600) < 0) goto err; - /* retry on collision */ + goto out; } errno = EEXIST; |
