1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

dmsetup: check timerfd reads for valid byte count (Coverity)

The timerfd guarantees that it will return 8 bytes when a read(2)
is issued (a uint64_t giving the number of timer events during the
call). Check that it does so and log a non-fatal error if the byte
count is not 8.
This commit is contained in:
Bryn M. Reeves 2015-08-17 19:26:44 +01:00
parent 074b5de771
commit 12acf852c5

View File

@ -573,18 +573,25 @@ static int _start_timerfd_timer(void)
static int _do_timerfd_wait(void)
{
uint64_t expired;
ssize_t bytes;
if (_timer_fd < 0)
return 0;
/* read on timerfd returns a uint64_t in host byte order. */
if (read(_timer_fd, &expired, sizeof(expired)) < 0) {
bytes = read(_timer_fd, &expired, sizeof(expired));
if (bytes < 0) {
/* EBADF from invalid timerfd or EINVAL from too small buffer. */
log_error("Interval timer wait failed: %s",
strerror(errno));
return 0;
}
/* read(2) on a timerfd descriptor is guaranteed to return 8 bytes. */
if (bytes != 8)
log_error("Unexepcted byte count on timerfd read: %d", bytes);
/* FIXME: attempt to rebase clock? */
if (expired > 1)
log_warn("WARNING: Try increasing --interval ("FMTu64