hw/xen: Check if len is 0 before memcpy()

data->data can be NULL when len is 0. Strictly speaking, the behavior
of memcpy() in such a scenario is undefined so UBSan complaints.

Satisfy UBSan by checking if len is 0 before memcpy().

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
This commit is contained in:
Akihiko Odaki 2025-01-08 20:31:46 +09:00 committed by David Woodhouse
parent 981780cdda
commit b6014c5089

View file

@ -532,6 +532,10 @@ static void xs_read(XenXenstoreState *s, unsigned int req_id,
return;
}
if (!len) {
return;
}
memcpy(&rsp_data[rsp->len], data->data, len);
rsp->len += len;
}