提交 341ba0df 编写于 作者: P Peter Maydell 提交者: Dr. David Alan Gilbert

migration/ram.c: Avoid taking address of fields in packed MultiFDInit_t struct

Taking the address of a field in a packed struct is a bad idea, because
it might not be actually aligned enough for that pointer type (and
thus cause a crash on dereference on some host architectures). Newer
versions of clang warn about this:

migration/ram.c:651:19: warning: taking address of packed member 'magic' of class or structure 'MultiFDInit_t' may result in an unaligned pointer value [-Waddress-of-packed-member]
migration/ram.c:652:19: warning: taking address of packed member 'version' of class or structure 'MultiFDInit_t' may result in an unaligned pointer value [-Waddress-of-packed-member]
migration/ram.c:737:19: warning: taking address of packed member 'magic' of class or structure 'MultiFDPacket_t' may result in an unaligned pointer value [-Waddress-of-packed-member]
migration/ram.c:745:19: warning: taking address of packed member 'version' of class or structure 'MultiFDPacket_t' may result in an unaligned pointer value [-Waddress-of-packed-member]
migration/ram.c:755:19: warning: taking address of packed member 'size' of class or structure 'MultiFDPacket_t' may result in an unaligned pointer value [-Waddress-of-packed-member]

Avoid the bug by not using the "modify in place" byteswapping
functions.
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
Message-Id: <20180925161924.7832-1-peter.maydell@linaro.org>
Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: NDr. David Alan Gilbert <dgilbert@redhat.com>
上级 05306935
...@@ -651,8 +651,8 @@ static int multifd_recv_initial_packet(QIOChannel *c, Error **errp) ...@@ -651,8 +651,8 @@ static int multifd_recv_initial_packet(QIOChannel *c, Error **errp)
return -1; return -1;
} }
be32_to_cpus(&msg.magic); msg.magic = be32_to_cpu(msg.magic);
be32_to_cpus(&msg.version); msg.version = be32_to_cpu(msg.version);
if (msg.magic != MULTIFD_MAGIC) { if (msg.magic != MULTIFD_MAGIC) {
error_setg(errp, "multifd: received packet magic %x " error_setg(errp, "multifd: received packet magic %x "
...@@ -737,7 +737,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) ...@@ -737,7 +737,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
RAMBlock *block; RAMBlock *block;
int i; int i;
be32_to_cpus(&packet->magic); packet->magic = be32_to_cpu(packet->magic);
if (packet->magic != MULTIFD_MAGIC) { if (packet->magic != MULTIFD_MAGIC) {
error_setg(errp, "multifd: received packet " error_setg(errp, "multifd: received packet "
"magic %x and expected magic %x", "magic %x and expected magic %x",
...@@ -745,7 +745,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) ...@@ -745,7 +745,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
return -1; return -1;
} }
be32_to_cpus(&packet->version); packet->version = be32_to_cpu(packet->version);
if (packet->version != MULTIFD_VERSION) { if (packet->version != MULTIFD_VERSION) {
error_setg(errp, "multifd: received packet " error_setg(errp, "multifd: received packet "
"version %d and expected version %d", "version %d and expected version %d",
...@@ -755,7 +755,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) ...@@ -755,7 +755,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
p->flags = be32_to_cpu(packet->flags); p->flags = be32_to_cpu(packet->flags);
be32_to_cpus(&packet->size); packet->size = be32_to_cpu(packet->size);
if (packet->size > migrate_multifd_page_count()) { if (packet->size > migrate_multifd_page_count()) {
error_setg(errp, "multifd: received packet " error_setg(errp, "multifd: received packet "
"with size %d and expected maximum size %d", "with size %d and expected maximum size %d",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册