From a7032da6bbe875596ea1cb348a747123cda7d408 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 7 Mar 2022 18:15:58 +0100 Subject: ipcpd: Fix memcpy with NULL in piggyback API If there is no piggyback data, memcpy was passed a NULL pointer in memcpy(buf, NULL, 0) calls, which is undefined behaviour. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/irmd/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/irmd/main.c') diff --git a/src/irmd/main.c b/src/irmd/main.c index fdbc25a7..fab9497d 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1698,8 +1698,8 @@ static int flow_req_arr(pid_t pid, } f->len = len; - - memcpy(f->data, data, len); + if (len > 0) + memcpy(f->data, data, len); } list_add(&f->next, &irmd.irm_flows); @@ -1764,7 +1764,9 @@ static int flow_alloc_reply(int flow_id, return -1; } - memcpy(f->data, data, len); + if (len > 0) + memcpy(f->data, data, len); + f->len = len; pthread_rwlock_unlock(&irmd.flows_lock); -- cgit v1.2.3