From: Tom Yu Date: Fri, 4 May 2001 04:22:50 +0000 (+0000) Subject: * dump-utmp.c: Fix some off-by-one errors. Handle cases where we X-Git-Tag: krb5-1.3-alpha1~1521 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9530b1f60e4048438cf54718a5e7baf92a269e87;p=krb5.git * dump-utmp.c: Fix some off-by-one errors. Handle cases where we have utmpname() but not utmpname(). git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13230 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/pty/ChangeLog b/src/util/pty/ChangeLog index 42f3a69eb..41e6a3456 100644 --- a/src/util/pty/ChangeLog +++ b/src/util/pty/ChangeLog @@ -1,5 +1,8 @@ 2001-05-04 Tom Yu + * dump-utmp.c: Fix some off-by-one errors. Handle cases where we + have utmpname() but not utmpname(). + * pty-int.h: Fix typo; VHANG_first -> VHANG_FIRST. * open_slave.c (pty_open_slave): Add workaround for Tru64 v5.0, diff --git a/src/util/pty/dump-utmp.c b/src/util/pty/dump-utmp.c index 81bb49ce2..6847ac9bc 100644 --- a/src/util/pty/dump-utmp.c +++ b/src/util/pty/dump-utmp.c @@ -231,13 +231,8 @@ main(int argc, char **argv) perror(fn); exit(1); } - do { - nread = read(f, &u, recsize); - if (nread == -1) { - perror("read"); - exit(1); - } - if (nread && nread < recsize) { + while ((nread = read(f, &u, recsize)) > 0) { + if (nread < recsize) { fprintf(stderr, "short read"); close(f); exit(1); @@ -251,15 +246,24 @@ main(int argc, char **argv) } else { print_ut(all, &u.ut); } - } while (nread); + } + if (nread == -1) { + perror("read"); + exit(1); + } close(f); } else { if (is_utmpx) { -#if defined(UTMPX) && defined(UTN) +#ifdef UTMPX +#ifdef HAVE_UTMPXNAME utmpxname(fn); setutxent(); while ((utxp = getutxent()) != NULL) print_utx(all, utxp); +#else + fprintf(stderr, "no utmpxname(); can't use getutxent()\n"); + exit(1); +#endif #else abort(); #endif @@ -270,7 +274,8 @@ main(int argc, char **argv) while ((utp = getutent()) != NULL) print_ut(all, utp); #else - abort(); + fprintf(stderr, "no utmpname(); can't use getutent()\n"); + exit(1); #endif } }