gen_uuid.c: Fix two Unchecked return value from library errors

CID 1049146: Unchecked return value from library in get_clock().
CID 1049147: Unchecked return value from library in get_random_fd().

Closes #4280
This commit is contained in:
Ryan Long
2021-03-02 11:08:28 -05:00
committed by Joel Sherrill
parent 3246fa42e2
commit 597e4f4765

View File

@@ -155,6 +155,7 @@ static int get_random_fd(void)
struct timeval tv; struct timeval tv;
static int fd = -2; static int fd = -2;
int i; int i;
int sc;
if (fd == -2) { if (fd == -2) {
gettimeofday(&tv, 0); gettimeofday(&tv, 0);
@@ -164,8 +165,10 @@ static int get_random_fd(void)
fd = open("/dev/random", O_RDONLY | O_NONBLOCK); fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
if (fd >= 0) { if (fd >= 0) {
i = fcntl(fd, F_GETFD); i = fcntl(fd, F_GETFD);
if (i >= 0) if (i >= 0) {
fcntl(fd, F_SETFD, i | FD_CLOEXEC); sc = fcntl(fd, F_SETFD, i | FD_CLOEXEC);
_Assert_Unused_variable_unequal(sc, -1);
}
} }
#endif #endif
srand((getpid() << ((sizeof(pid_t)*CHAR_BIT)>>1)) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); srand((getpid() << ((sizeof(pid_t)*CHAR_BIT)>>1)) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
@@ -334,6 +337,7 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
uint64_t clock_reg; uint64_t clock_reg;
mode_t save_umask; mode_t save_umask;
int len; int len;
int sc;
if (state_fd == -2) { if (state_fd == -2) {
save_umask = umask(0); save_umask = umask(0);
@@ -426,7 +430,8 @@ try_again:
} }
rewind(state_f); rewind(state_f);
fl.l_type = F_UNLCK; fl.l_type = F_UNLCK;
fcntl(state_fd, F_SETLK, &fl); sc = fcntl(state_fd, F_SETLK, &fl);
_Assert_Unused_variable_unequal(sc, -1);
} }
*clock_high = clock_reg >> 32; *clock_high = clock_reg >> 32;