From: tholo Date: Sat, 29 Mar 1997 20:28:20 +0000 (+0000) Subject: Avoid infinite loops; from NetBSD PR 3285 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c0edfbda20a6dbb1d064a67a57081e52d533023a;p=openbsd Avoid infinite loops; from NetBSD PR 3285 --- 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);