hw/xen: Check if len is 0 before memcpy()
PATCH 1/1 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().
--- hw/i386/kvm/xen_xenstore.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/i386/kvm/xen_xenstore.c +4 -0
@@ -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; }
---
base-commit: 38d0939b86e2eef6f6a622c6f1f7befda0146595
change-id: 20241227-xen-fb5a15cc0ca7
Best regards,
Signature · 1 line
Akihiko Odaki <[email protected]>
Quoted 9 lines · Akihiko Odaki
data->datacan be NULL when len is 0. Strictly speaking, the behavior ofmemcpy()in such a scenario is undefined so UBSan complaints.Satisfy UBSan by checking if len is 0 before
memcpy().Signed-off-by Akihiko Odaki <[email protected]>--- hw/i386/kvm/xen_xenstore.c | 4 ++++ 1 file changed, 4 insertions(+)
Quoted 6 lines · Akihiko Odaki
data->datacan be NULL when len is 0. Strictly speaking, the behavior ofmemcpy()in such a scenario is undefined so UBSan complaints.Satisfy UBSan by checking if len is 0 before
memcpy().Signed-off-by Akihiko Odaki <[email protected]>
Thanks.
Quoted 26 lines
---
hw/i386/kvm/xen_xenstore.c | 4 ++++1 file changed, 4 insertions(+)hw/i386/kvm/xen_xenstore.c +0
-0@@ -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;
}---
base-commit:38d0939b86e2eef6f6a622c6f1f7befda0146595
change-id: 20241227-xen-fb5a15cc0ca7Best regards,