summaryrefslogtreecommitdiffstats
path: root/lib/libutil/imsg.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2015-07-19 07:18:59 +0000
committernicm <nicm@openbsd.org>2015-07-19 07:18:59 +0000
commitaa53a3a52577c82f81b38c32b2dd1232c882a882 (patch)
treeb74ca8288531620b161316dd19b4e2bb702934e2 /lib/libutil/imsg.c
parentTrailing spaces and missing .Pp. (diff)
downloadwireguard-openbsd-aa53a3a52577c82f81b38c32b2dd1232c882a882.tar.xz
wireguard-openbsd-aa53a3a52577c82f81b38c32b2dd1232c882a882.zip
Handle malloc(0) returning NULL (which can happen on some other
platforms) by explicitly making imsg->data = NULL when there is no data. ok deraadt
Diffstat (limited to 'lib/libutil/imsg.c')
-rw-r--r--lib/libutil/imsg.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/libutil/imsg.c b/lib/libutil/imsg.c
index 8fb349273f2..5b1a7c13cf4 100644
--- a/lib/libutil/imsg.c
+++ b/lib/libutil/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.9 2015/07/12 18:40:49 nicm Exp $ */
+/* $OpenBSD: imsg.c,v 1.10 2015/07/19 07:18:59 nicm Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -143,7 +143,9 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
return (0);
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
- if ((imsg->data = malloc(datalen)) == NULL)
+ if (datalen == 0)
+ imsg->data = NULL;
+ else if ((imsg->data = malloc(datalen)) == NULL)
return (-1);
if (imsg->hdr.flags & IMSGF_HASFD)