From 151af94ebac619594e1f4599e395b8946cb47d32 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Fri, 28 Jan 2022 12:34:42 +0000 Subject: 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.) --- compat/imsg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'compat') 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 @@ -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; -- cgit v1.2.3