From: Theodore Ts'o Date: Sat, 11 Jan 2014 02:06:07 +0000 (-0500) Subject: libuuid: add error checking to syscalls in get_clock() X-Git-Tag: v1.42.10~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7d7905976d2db2497a0b2b87a73fc85e92ff808;p=thirdparty%2Fe2fsprogs.git libuuid: add error checking to syscalls in get_clock() Also remove redundant close() of state_fd, since the fclose() of state_f will result in the fd being closed. Addresses-Coverity-Id: #1049146 Addresses-Coverity-Id: #26092 Signed-off-by: "Theodore Ts'o" --- diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c index 1b23d112a..22b451342 100644 --- a/lib/uuid/gen_uuid.c +++ b/lib/uuid/gen_uuid.c @@ -326,10 +326,12 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low, state_fd = open("/var/lib/libuuid/clock.txt", O_RDWR|O_CREAT, 0660); (void) umask(save_umask); - state_f = fdopen(state_fd, "r+"); - if (!state_f) { - close(state_fd); - state_fd = -1; + if (state_fd >= 0) { + state_f = fdopen(state_fd, "r+"); + if (!state_f) { + close(state_fd); + state_fd = -1; + } } } fl.l_type = F_WRLCK; @@ -343,7 +345,6 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low, if ((errno == EAGAIN) || (errno == EINTR)) continue; fclose(state_f); - close(state_fd); state_fd = -1; break; } @@ -412,7 +413,10 @@ try_again: } rewind(state_f); fl.l_type = F_UNLCK; - fcntl(state_fd, F_SETLK, &fl); + if (fcntl(state_fd, F_SETLK, &fl) < 0) { + fclose(state_f); + state_fd = -1; + } } *clock_high = clock_reg >> 32;