From 76c0ce9a3599191b646311069f2c7e11a3be5098 Mon Sep 17 00:00:00 2001 From: millert Date: Mon, 13 Mar 2000 04:05:13 +0000 Subject: [PATCH] Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between reads at just the right time is is possible to get duplicate output but in practice this is extremely rare. Joint effort with Theo. --- sys/kern/subr_prf.c | 3 ++- sys/miscfs/kernfs/kernfs_vnops.c | 21 ++++++++++++++------- sys/sys/msgbuf.h | 3 ++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 5ab131ddc8d..5bd4b69546d 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_prf.c,v 1.28 2000/03/02 10:50:29 art Exp $ */ +/* $OpenBSD: subr_prf.c,v 1.29 2000/03/13 04:05:15 millert Exp $ */ /* $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $ */ /*- @@ -335,6 +335,7 @@ putchar(c, flags, tp) /* Nothing we can do */ } mbp->msg_bufc[mbp->msg_bufx++] = c; + mbp->msg_bufl = min(mbp->msg_bufl+1, mbp->msg_bufs); if (mbp->msg_bufx < 0 || mbp->msg_bufx >= mbp->msg_bufs) mbp->msg_bufx = 0; /* If the buffer is full, keep the most recent data. */ diff --git a/sys/miscfs/kernfs/kernfs_vnops.c b/sys/miscfs/kernfs/kernfs_vnops.c index 23922ae3343..160e437ed0a 100644 --- a/sys/miscfs/kernfs/kernfs_vnops.c +++ b/sys/miscfs/kernfs/kernfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kernfs_vnops.c,v 1.18 2000/02/22 19:28:06 deraadt Exp $ */ +/* $OpenBSD: kernfs_vnops.c,v 1.19 2000/03/13 04:05:15 millert Exp $ */ /* $NetBSD: kernfs_vnops.c,v 1.43 1996/03/16 23:52:47 christos Exp $ */ /* @@ -269,12 +269,19 @@ kernfs_xread(kt, off, bufp, len) * message buffer header are corrupted, but that'll cause * the system to die anyway. */ - if (off >= msgbufp->msg_bufs) - return (0); - n = msgbufp->msg_bufx + off; - if (n >= msgbufp->msg_bufs) - n -= msgbufp->msg_bufs; - len = min(msgbufp->msg_bufs - n, msgbufp->msg_bufs - off); + if (msgbufp->msg_bufl < msgbufp->msg_bufs) { + if (off >= msgbufp->msg_bufx) + return (0); + n = off; + len = msgbufp->msg_bufx - n; + } else { + if (off >= msgbufp->msg_bufs) + return (0); + n = msgbufp->msg_bufx + off; + if (n >= msgbufp->msg_bufs) + n -= msgbufp->msg_bufs; + len = min(msgbufp->msg_bufs - n, msgbufp->msg_bufs - off); + } *bufp = msgbufp->msg_bufc + n; return (len); } diff --git a/sys/sys/msgbuf.h b/sys/sys/msgbuf.h index 1214c4cbc8d..a09cc13dc5c 100644 --- a/sys/sys/msgbuf.h +++ b/sys/sys/msgbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: msgbuf.h,v 1.3 2000/02/22 19:28:05 deraadt Exp $ */ +/* $OpenBSD: msgbuf.h,v 1.4 2000/03/13 04:05:13 millert Exp $ */ /* $NetBSD: msgbuf.h,v 1.8 1995/03/26 20:24:27 jtc Exp $ */ /* @@ -42,6 +42,7 @@ struct msgbuf { long msg_bufx; /* write pointer */ long msg_bufr; /* read pointer */ long msg_bufs; /* real msg_bufc size (bytes) */ + long msg_bufl; /* # chars, <= msg_bufs */ char msg_bufc[1]; /* buffer */ }; #ifdef _KERNEL -- 2.20.1