summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2019-12-24 13:20:45 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2019-12-24 13:20:45 +0000
commit7a0833ec796c60cabcb66ac2bfe757e7ac584448 (patch)
tree11cb8958cff6aac220c033eb17a2b5c16370aa85 /sbin
parentb8266546459c7e213edb1d74de23b97f989a244a (diff)
dmesg(8) allocated a bit too much memory due to padding of struct
msgbuf. Use the same size algorithm in kernel and userland. OK cheloha@ guenther@ deraadt@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/dmesg/dmesg.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c
index 6c30f1a0c86..4d63370e9ab 100644
--- a/sbin/dmesg/dmesg.c
+++ b/sbin/dmesg/dmesg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dmesg.c,v 1.30 2018/05/15 15:15:50 cheloha Exp $ */
+/* $OpenBSD: dmesg.c,v 1.31 2019/12/24 13:20:44 bluhm Exp $ */
/* $NetBSD: dmesg.c,v 1.8 1995/03/18 14:54:49 cgd Exp $ */
/*-
@@ -39,6 +39,7 @@
#include <kvm.h>
#include <limits.h>
#include <nlist.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -99,7 +100,7 @@ main(int argc, char *argv[])
err(1, "sysctl: %s", startupmsgs ? "KERN_CONSBUFSIZE" :
"KERN_MSGBUFSIZE");
- msgbufsize += sizeof(struct msgbuf) - 1;
+ msgbufsize += offsetof(struct msgbuf, msg_bufc);
allocated = bufdata = calloc(1, msgbufsize);
if (bufdata == NULL)
errx(1, "couldn't allocate space for buffer data");