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/ipcpd/eth/eth.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/ipcpd/eth') diff --git a/src/ipcpd/eth/eth.c b/src/ipcpd/eth/eth.c index f62bd0a7..25f42fc8 100644 --- a/src/ipcpd/eth/eth.c +++ b/src/ipcpd/eth/eth.c @@ -496,7 +496,8 @@ static int eth_ipcp_alloc(const uint8_t * dst_addr, msg->timeout = hton32(qs.timeout); memcpy(msg + 1, hash, ipcp_dir_hash_len()); - memcpy(buf + len + ETH_HEADER_TOT_SIZE, data, dlen); + if (dlen > 0) + memcpy(buf + len + ETH_HEADER_TOT_SIZE, data, dlen); ret = eth_ipcp_send_frame(dst_addr, #if defined(BUILD_ETH_DIX) @@ -542,7 +543,8 @@ static int eth_ipcp_alloc_resp(uint8_t * dst_addr, #endif msg->response = response; - memcpy(msg + 1, data, len); + if (len > 0) + memcpy(msg + 1, data, len); if (eth_ipcp_send_frame(dst_addr, #if defined(BUILD_ETH_DIX) -- cgit v1.2.3