From: tedu Date: Mon, 3 Apr 2017 17:23:39 +0000 (+0000) Subject: check return from pread, don't divide -1 for count X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=db006180e56b790d51443987f96346d99e672470;p=openbsd check return from pread, don't divide -1 for count --- diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c index ef9a0b4d18e..df7283b29ac 100644 --- a/libexec/comsat/comsat.c +++ b/libexec/comsat/comsat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: comsat.c,v 1.47 2017/04/03 17:07:58 deraadt Exp $ */ +/* $OpenBSD: comsat.c,v 1.48 2017/04/03 17:23:39 tedu Exp $ */ /* * Copyright (c) 1980, 1993 @@ -170,6 +170,7 @@ doreadutmp(void) static u_int utmpsize; /* last malloced size for utmp */ static time_t utmpmtime; /* last modification time for utmp */ struct stat statbf; + int n; if (time(NULL) - lastmsgtime >= MAXIDLE) exit(0); @@ -195,7 +196,10 @@ doreadutmp(void) utmp = u; utmpsize = nutmpsize; } - nutmp = pread(uf, utmp, statbf.st_size, 0)/sizeof(struct utmp); + n = pread(uf, utmp, statbf.st_size, 0); + if (n == -1) + n = 0; + nutmp = n / sizeof(struct utmp); dsyslog(LOG_DEBUG, "read %d utmp entries", nutmp); } (void)alarm(15);