qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] hd-geo-test: Clean up use of buf[] in create_qcow2_with_mbr(


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH] hd-geo-test: Clean up use of buf[] in create_qcow2_with_mbr()
Date: Tue, 17 Mar 2020 10:28:31 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 3/17/20 10:23 AM, Markus Armbruster wrote:
valgrind reports write unitialized bytes from buf[].  Clear them.

ASan reports we store to misaligned address in buf[].  Use stl_le_p()
for that.

Cc: Sam Eiderman <address@hidden>
Cc: John Snow <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
  tests/qtest/hd-geo-test.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index a249800544..48e8e02d6e 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -421,7 +421,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, 
uint64_t sectors)
      char *raw_path = strdup(template);
      char *qcow2_path = strdup(template);
      char cmd[100 + 2 * PATH_MAX];
-    uint8_t buf[512];
+    uint8_t buf[512] = {};
      int i, ret, fd, offset;
      uint64_t qcow2_size = sectors * 512;
      uint8_t status, parttype, head, sector, cyl;
@@ -457,8 +457,8 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, 
uint64_t sectors)
          buf[offset + 0x6] = sector;
          buf[offset + 0x7] = cyl;
- (*(uint32_t *)&buf[offset + 0x8]) = cpu_to_le32(mbr[i].start_sect);
-        (*(uint32_t *)&buf[offset + 0xc]) = cpu_to_le32(mbr[i].nr_sects);
+        stl_le_p(&buf[offset + 0x8], mbr[i].start_sect);
+        stl_le_p(&buf[offset + 0xc], mbr[i].nr_sects);
offset += 0x10;
      }


Reviewed-by: Philippe Mathieu-Daudé <address@hidden>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]