summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2022-01-28 10:41:45 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2022-01-28 10:41:45 +0000
commit31add6b3965b98628881f5b828c161cfdeb2a942 (patch)
treea011e2964c87467c65b618cdba0c0dc53878851f /lib
parentf6d45d9124464288e8a6d8d2fcf534de9427c274 (diff)
Only memcpy() into imsg->data if datalen is not 0. Passing a NULL pointer
to memcpy() is UB no matter if len is 0. Reported by fouzhe on openbgpd-portable github page. OK tb@
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/imsg.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/libutil/imsg.c b/lib/libutil/imsg.c
index c0ff22978e0..b381b1edd47 100644
--- a/lib/libutil/imsg.c
+++ b/lib/libutil/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.16 2017/12/14 09:27:44 kettenis Exp $ */
+/* $OpenBSD: imsg.c,v 1.17 2022/01/28 10:41:44 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -150,7 +150,8 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
else
imsg->fd = -1;
- memcpy(imsg->data, ibuf->r.rptr, datalen);
+ if (datalen != 0)
+ memcpy(imsg->data, ibuf->r.rptr, datalen);
if (imsg->hdr.len < av) {
left = av - imsg->hdr.len;