aboutsummaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2022-01-28 12:34:42 +0000
committerOmar Polo <op@omarpolo.com>2022-01-28 12:34:42 +0000
commit151af94ebac619594e1f4599e395b8946cb47d32 (patch)
tree6c1c48f80ad08aebf0ff9fbc6ae0498e58cfb573 /compat
parent12a5e730e975767f3ba4adbb3b0b50236b8f830c (diff)
only memcpy into imsg->data if datalen is not zero
Passing a NULL pointer to memcpy is UB no matter if len is 0 (commit by claudio@, backporting for gmid.)
Diffstat (limited to 'compat')
-rw-r--r--compat/imsg.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/compat/imsg.c b/compat/imsg.c
index 3d36a40..74aead2 100644
--- a/compat/imsg.c
+++ b/compat/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>
@@ -151,7 +151,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;