diff options
author | Peter Maydell | 2017-03-27 19:59:04 +0200 |
---|---|---|
committer | Greg Kurz | 2017-03-27 21:15:31 +0200 |
commit | 34ef723ce34aaa14f94530c06a0ab3170a19bb59 (patch) | |
tree | 85a23ddd9e52365fb6978f0548f0b72396ecfad0 /tests | |
parent | 9pfs: fix file descriptor leak (diff) | |
download | qemu-34ef723ce34aaa14f94530c06a0ab3170a19bb59.tar.gz qemu-34ef723ce34aaa14f94530c06a0ab3170a19bb59.tar.xz qemu-34ef723ce34aaa14f94530c06a0ab3170a19bb59.zip |
tests/virtio-9p-test: Don't call le*_to_cpus on fields of packed struct
For a packed struct like 'P9Hdr' the fields within it may not be
aligned as much as the natural alignment for their types. This means
it is not valid to pass the address of such a field to a function
like le32_to_cpus() which operate on uint32_t* and assume alignment.
Doing this results in a SIGBUS on hosts like SPARC which have strict
alignment requirements.
Use ldl_le_p() instead, which is specified to correctly handle
unaligned pointers.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Greg Kurz <groug@kaod.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/virtio-9p-test.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index 43a1ad813f..ad33d96387 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -256,8 +256,8 @@ static void v9fs_req_recv(P9Req *req, uint8_t id) qvirtio_wait_queue_isr(v9p->dev, v9p->vq, 1000 * 1000); v9fs_memread(req, &hdr, 7); - le32_to_cpus(&hdr.size); - le16_to_cpus(&hdr.tag); + hdr.size = ldl_le_p(&hdr.size); + hdr.tag = lduw_le_p(&hdr.tag); if (hdr.size >= 7) { break; } |