diff options
Diffstat (limited to 'util')
| -rw-r--r-- | util/libreboot-utils/lib/file.c | 14 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/io.c | 7 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/mkhtemp.c | 23 | ||||
| -rw-r--r-- | util/libreboot-utils/nvmutil.c | 5 |
4 files changed, 36 insertions, 13 deletions
diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c index 805db726..12f52c56 100644 --- a/util/libreboot-utils/lib/file.c +++ b/util/libreboot-utils/lib/file.c @@ -826,12 +826,14 @@ close_on_eintr(int *fd) * ONE MACRO TO RULE THEM ALL: */ #define fs_err_retry() \ - if ((rval == -1) && \ - (errno == EINTR)) \ - return 1; \ - if (rval >= 0 && !errno) \ - errno = saved_errno; \ - return 0 + do { \ + if ((rval == -1) && \ + (errno == EINTR)) \ + return 1; \ + if (rval >= 0 && !errno) \ + errno = saved_errno; \ + return 0; \ + } while(0) /* * Regarding the errno logic above: * on success, it is permitted that diff --git a/util/libreboot-utils/lib/io.c b/util/libreboot-utils/lib/io.c index 9bbf1f30..56f8528a 100644 --- a/util/libreboot-utils/lib/io.c +++ b/util/libreboot-utils/lib/io.c @@ -28,6 +28,8 @@ open_gbe_file(void) struct xstate *x = xstatus(); struct commands *cmd = &x->cmd[x->i]; struct xfile *f = &x->f; + int saved_errno = errno; + errno = 0; int _flags; @@ -46,7 +48,8 @@ open_gbe_file(void) if (f->gbe_st.st_nlink == 0) err_exit(EIO, "%s: file unlinked while open", f->fname); - _flags = fcntl(f->gbe_fd, F_GETFL); + while (fs_retry(saved_errno, + _flags = fcntl(f->gbe_fd, F_GETFL))); if (_flags == -1) err_exit(errno, "%s: fcntl(F_GETFL)", f->fname); @@ -74,6 +77,8 @@ open_gbe_file(void) if (lock_file(f->gbe_fd, cmd->flags) == -1) err_exit(errno, "%s: can't lock", f->fname); */ + + reset_caller_errno(0); } void diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c index c1574634..d3ca92b0 100644 --- a/util/libreboot-utils/lib/mkhtemp.c +++ b/util/libreboot-utils/lib/mkhtemp.c @@ -699,6 +699,10 @@ mkhtemp_tmpfile_linux(int dirfd, 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) @@ -740,15 +744,21 @@ int secure_file(int *fd, int do_lock, mode_t mode) { - int flags; + int flags = -1; struct stat st_now; int saved_errno = errno; errno = 0; if (if_err(fd == NULL || st == NULL, EFAULT) || - if_err(*fd < 0, EBADF) || - if_err_sys((flags = fcntl(*fd, F_GETFL)) == -1) || - if_err(bad_flags > 0 && (flags & bad_flags), EPERM)) + if_err(*fd < 0, EBADF)) + goto err_demons; + + while (fs_retry(saved_errno, + flags = fcntl(*fd, F_GETFL))); + if (flags == -1) + goto err_demons; + + if (if_err(bad_flags > 0 && (flags & bad_flags), EPERM)) goto err_demons; if (expected != NULL) { @@ -874,6 +884,7 @@ lock_file(int fd, int flags) { struct flock fl; int saved_errno = errno; + int fcntl_rval = -1; errno = 0; if (if_err(fd < 0, EBADF) || @@ -889,7 +900,9 @@ lock_file(int fd, int flags) fl.l_whence = SEEK_SET; - if (fcntl(fd, F_SETLK, &fl) == -1) + while (fs_retry(saved_errno, + fcntl_rval = fcntl(fd, F_SETLK, &fl))); + if (fcntl_rval == -1) goto err_lock_file; reset_caller_errno(0); diff --git a/util/libreboot-utils/nvmutil.c b/util/libreboot-utils/nvmutil.c index 3102bd50..26d15145 100644 --- a/util/libreboot-utils/nvmutil.c +++ b/util/libreboot-utils/nvmutil.c @@ -32,8 +32,11 @@ main(int argc, char *argv[]) struct xfile *f; size_t c; - (void) errhook(exit_cleanup); (void) lbsetprogname(argv[0]); + if (argc < 3) + usage(); + + (void) errhook(exit_cleanup); /* https://man.openbsd.org/pledge.2 */ /* https://man.openbsd.org/unveil.2 */ |
