summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2000-03-13 04:05:13 +0000
committermillert <millert@openbsd.org>2000-03-13 04:05:13 +0000
commit76c0ce9a3599191b646311069f2c7e11a3be5098 (patch)
tree7806640171de5c584d84d14e44a5c36bdaecc677
parentavoid unused variable by #ifdef (diff)
downloadwireguard-openbsd-76c0ce9a3599191b646311069f2c7e11a3be5098.tar.xz
wireguard-openbsd-76c0ce9a3599191b646311069f2c7e11a3be5098.zip
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.
-rw-r--r--sys/kern/subr_prf.c3
-rw-r--r--sys/miscfs/kernfs/kernfs_vnops.c21
-rw-r--r--sys/sys/msgbuf.h3
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