From 597bb764f12b7a4b47ad45859af6ebe887de8da7 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Thu, 2 Jun 2011 20:26:30 +0000 Subject: [PATCH] * src/lastlog.c, src/faillog.c: Fix underflows causing wrong entry to be displayed. --- ChangeLog | 5 +++++ src/faillog.c | 12 ++++++------ src/lastlog.c | 5 ++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b7a3290a..d3a1a1b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-02 Peter Vrabec + + * src/lastlog.c, src/faillog.c: Fix underflows causing wrong entry + to be displayed. + 2011-06-02 Nicolas François * libmisc/xmalloc.c: Harmonize message. diff --git a/src/faillog.c b/src/faillog.c index 8c10cab7..2742f2ee 100644 --- a/src/faillog.c +++ b/src/faillog.c @@ -118,8 +118,8 @@ static void print_one (/*@null@*/const struct passwd *pw, bool force) return; } - offset = pw->pw_uid * sizeof (fl); - if (offset <= (statbuf.st_size - sizeof (fl))) { + offset = (off_t) pw->pw_uid * sizeof (fl); + if (offset + sizeof (fl) <= statbuf.st_size) { /* fseeko errors are not really relevant for us. */ int err = fseeko (fail, offset, SEEK_SET); assert (0 == err); @@ -218,8 +218,8 @@ static bool reset_one (uid_t uid) off_t offset; struct faillog fl; - offset = uid * sizeof (fl); - if (offset <= (statbuf.st_size - sizeof (fl))) { + offset = (off_t) uid * sizeof (fl); + if (offset + sizeof (fl) <= statbuf.st_size) { /* fseeko errors are not really relevant for us. */ int err = fseeko (fail, offset, SEEK_SET); assert (0 == err); @@ -333,7 +333,7 @@ static bool setmax_one (uid_t uid, int max) struct faillog fl; offset = (off_t) uid * sizeof (fl); - if (offset <= (statbuf.st_size - sizeof (fl))) { + if (offset + sizeof (fl) <= statbuf.st_size) { /* fseeko errors are not really relevant for us. */ int err = fseeko (fail, offset, SEEK_SET); assert (0 == err); @@ -450,7 +450,7 @@ static bool set_locktime_one (uid_t uid, long locktime) struct faillog fl; offset = (off_t) uid * sizeof (fl); - if (offset <= (statbuf.st_size - sizeof (fl))) { + if (offset + sizeof (fl) <= statbuf.st_size) { /* fseeko errors are not really relevant for us. */ int err = fseeko (fail, offset, SEEK_SET); assert (0 == err); diff --git a/src/lastlog.c b/src/lastlog.c index 43008c75..83e3a508 100644 --- a/src/lastlog.c +++ b/src/lastlog.c @@ -102,9 +102,8 @@ static void print_one (/*@null@*/const struct passwd *pw) } - offset = pw->pw_uid * sizeof (ll); - - if (offset <= (statbuf.st_size - sizeof (ll))) { + offset = (off_t) pw->pw_uid * sizeof (ll); + if (offset + sizeof (ll) <= statbuf.st_size) { /* fseeko errors are not really relevant for us. */ int err = fseeko (lastlogfile, offset, SEEK_SET); assert (0 == err);