From 3361d8512c4d6dfeda55280a077d951a3382ddae Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 23 Jun 2023 11:52:23 +0200 Subject: Fix error handling in key2root-rmkey on failure to commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- key2root-rmkey.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'key2root-rmkey.c') diff --git a/key2root-rmkey.c b/key2root-rmkey.c index 82f04eb..dd7274d 100644 --- a/key2root-rmkey.c +++ b/key2root-rmkey.c @@ -210,14 +210,18 @@ out: fprintf(stderr, "%s: open %s O_WRONLY|O_CREAT|O_EXCL 0600: %s\n", argv0, path2, strerror(errno)); exit(1); } - if (writeall(fd, data, data_len) || close(fd)) { + if (writeall(fd, data, data_len)) { fprintf(stderr, "%s: write %s: %s\n", argv0, path2, strerror(errno)); - if (unlink(path2)) - fprintf(stderr, "%s: unlink %s: %s\n", argv0, path2, strerror(errno)); - exit(1); + close(fd) + goto saved_failed; + } + if (close(fd)) { + fprintf(stderr, "%s: write %s: %s\n", argv0, path2, strerror(errno)); + goto saved_failed; } if (rename(path2, path)) { fprintf(stderr, "%s: rename %s %s: %s\n", argv0, path2, path, strerror(errno)); + saved_failed: if (unlink(path2)) fprintf(stderr, "%s: unlink %s: %s\n", argv0, path2, strerror(errno)); exit(1); -- cgit v1.2.3-70-g09d2