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.)
This commit is contained in:
Omar Polo 2022-01-28 12:34:42 +00:00
parent 12a5e730e9
commit 151af94eba
1 changed files with 3 additions and 2 deletions

View File

@ -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;