diff options
author | Thorsten Lockert <tholo@cvs.openbsd.org> | 1997-03-29 20:28:21 +0000 |
---|---|---|
committer | Thorsten Lockert <tholo@cvs.openbsd.org> | 1997-03-29 20:28:21 +0000 |
commit | 0ef8febae96ef15812547a6baf1fcae9592bad0b (patch) | |
tree | 68709ce09368909116d8daa6832955732d84b0f0 | |
parent | 69c500c2b14baf0dd479e7a0b54fe93098f1d501 (diff) |
Avoid infinite loops; from NetBSD PR 3285
-rw-r--r-- | sbin/dmesg/dmesg.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c index 9e63bd76a53..e0475239c82 100644 --- a/sbin/dmesg/dmesg.c +++ b/sbin/dmesg/dmesg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dmesg.c,v 1.4 1997/01/15 23:41:10 millert Exp $ */ +/* $OpenBSD: dmesg.c,v 1.5 1997/03/29 20:28:20 tholo Exp $ */ /* $NetBSD: dmesg.c,v 1.8 1995/03/18 14:54:49 cgd Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$OpenBSD: dmesg.c,v 1.4 1997/01/15 23:41:10 millert Exp $"; +static char rcsid[] = "$OpenBSD: dmesg.c,v 1.5 1997/03/29 20:28:20 tholo Exp $"; #endif #endif /* not lint */ @@ -129,10 +129,10 @@ main(argc, argv) * The message buffer is circular; start at the read pointer, and * go to the write pointer - 1. */ - p = cur.msg_bufc + cur.msg_bufx; - ep = cur.msg_bufc + cur.msg_bufx - 1; - for (newl = skip = 0; p != ep; ++p) { - if (p == cur.msg_bufc + MSG_BSIZE) + p = ep = cur.msg_bufc + (cur.msg_bufx - 1 + MSG_BSIZE) % MSG_BSIZE; + newl = skip = 0; + do { + if (++p == cur.msg_bufc + MSG_BSIZE) p = cur.msg_bufc; ch = *p; /* Skip "\n<.*>" syslog sequences. */ @@ -153,7 +153,7 @@ main(argc, argv) (void)putchar(buf[0]); else (void)printf("%s", buf); - } + } while (p != ep); if (!newl) (void)putchar('\n'); exit(0); |