]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libuuid: add error checking to syscalls in get_clock()
authorTheodore Ts'o <tytso@mit.edu>
Sat, 11 Jan 2014 02:06:07 +0000 (21:06 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 11 Jan 2014 02:06:07 +0000 (21:06 -0500)
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" <tytso@mit.edu>
lib/uuid/gen_uuid.c

index 1b23d112a11997cbc7cb8e69fa2c97c033ee767d..22b451342435f65851fbc3e00a7feab4cad00ba5 100644 (file)
@@ -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;