[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/36] block/qcow: Don't take address of fields in pa
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 05/36] block/qcow: Don't take address of fields in packed structs |
Date: |
Mon, 5 Nov 2018 17:37:13 +0100 |
From: Peter Maydell <address@hidden>
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. Avoid the bug by not using the
"modify in place" byte swapping functions.
There are a few places where the in-place swap function is
used on something other than a packed struct field; we convert
those anyway, for consistency.
This patch was produced with the following spatch script:
@@
expression E;
@@
-be16_to_cpus(&E);
+E = be16_to_cpu(E);
@@
expression E;
@@
-be32_to_cpus(&E);
+E = be32_to_cpu(E);
@@
expression E;
@@
-be64_to_cpus(&E);
+E = be64_to_cpu(E);
@@
expression E;
@@
-cpu_to_be16s(&E);
+E = cpu_to_be16(E);
@@
expression E;
@@
-cpu_to_be32s(&E);
+E = cpu_to_be32(E);
@@
expression E;
@@
-cpu_to_be64s(&E);
+E = cpu_to_be64(E);
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Tested-by: John Snow <address@hidden>
Reviewed-by: John Snow <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/block/qcow.c b/block/qcow.c
index 385d935258..4518cb4c35 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -140,14 +140,14 @@ static int qcow_open(BlockDriverState *bs, QDict
*options, int flags,
if (ret < 0) {
goto fail;
}
- be32_to_cpus(&header.magic);
- be32_to_cpus(&header.version);
- be64_to_cpus(&header.backing_file_offset);
- be32_to_cpus(&header.backing_file_size);
- be32_to_cpus(&header.mtime);
- be64_to_cpus(&header.size);
- be32_to_cpus(&header.crypt_method);
- be64_to_cpus(&header.l1_table_offset);
+ header.magic = be32_to_cpu(header.magic);
+ header.version = be32_to_cpu(header.version);
+ header.backing_file_offset = be64_to_cpu(header.backing_file_offset);
+ header.backing_file_size = be32_to_cpu(header.backing_file_size);
+ header.mtime = be32_to_cpu(header.mtime);
+ header.size = be64_to_cpu(header.size);
+ header.crypt_method = be32_to_cpu(header.crypt_method);
+ header.l1_table_offset = be64_to_cpu(header.l1_table_offset);
if (header.magic != QCOW_MAGIC) {
error_setg(errp, "Image not in qcow format");
@@ -270,7 +270,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options,
int flags,
}
for(i = 0;i < s->l1_size; i++) {
- be64_to_cpus(&s->l1_table[i]);
+ s->l1_table[i] = be64_to_cpu(s->l1_table[i]);
}
/* alloc L2 cache (max. 64k * 16 * 8 = 8 MB) */
--
2.19.1
- [Qemu-devel] [PULL 00/36] Block layer patches, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 02/36] block: replace "discard" literal with BDRV_OPT_DISCARD macro, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 03/36] qemu-io-cmds: Fix two format strings, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 01/36] block/vvfat: Fix crash when reporting error about too many files in directory, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 07/36] crypto: initialize sector size even when opening with no IO flag, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 04/36] block/qcow2: Don't take address of fields in packed structs, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 05/36] block/qcow: Don't take address of fields in packed structs,
Kevin Wolf <=
- [Qemu-devel] [PULL 06/36] block/qcow2-bitmap: Don't take address of fields in packed structs, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 08/36] qcow2: Get the request alignment for encrypted images from QCryptoBlock, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 09/36] block: change some function return type to bool, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 10/36] iotests: make 083 specific to raw, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 12/36] block/vhdx: Don't take address of fields in packed structs, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 22/36] block: Require auto-read-only for existing fallbacks, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 15/36] quorum: Return an error if the blkverify mode has invalid settings, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 30/36] option: Make option help nicer to read, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 19/36] block: Update flags in bdrv_set_read_only(), Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 31/36] chardev: Indent list of chardevs, Kevin Wolf, 2018/11/05