* [PATCH] hd-geo-test: Clean up use of buf[] in create_qcow2_with_mbr()
@ 2020-03-17 9:23 Markus Armbruster
2020-03-17 9:28 ` Philippe Mathieu-Daudé
2020-03-17 16:19 ` John Snow
0 siblings, 2 replies; 3+ messages in thread
From: Markus Armbruster @ 2020-03-17 9:23 UTC (permalink / raw)
To: qemu-devel; +Cc: John Snow, Sam Eiderman
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 <shmuel.eiderman@oracle.com>
Cc: John Snow <jsnow@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
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;
}
--
2.21.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hd-geo-test: Clean up use of buf[] in create_qcow2_with_mbr()
2020-03-17 9:23 [PATCH] hd-geo-test: Clean up use of buf[] in create_qcow2_with_mbr() Markus Armbruster
@ 2020-03-17 9:28 ` Philippe Mathieu-Daudé
2020-03-17 16:19 ` John Snow
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-03-17 9:28 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: Sam Eiderman, John Snow
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 <shmuel.eiderman@oracle.com>
> Cc: John Snow <jsnow@redhat.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> 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é <philmd@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hd-geo-test: Clean up use of buf[] in create_qcow2_with_mbr()
2020-03-17 9:23 [PATCH] hd-geo-test: Clean up use of buf[] in create_qcow2_with_mbr() Markus Armbruster
2020-03-17 9:28 ` Philippe Mathieu-Daudé
@ 2020-03-17 16:19 ` John Snow
1 sibling, 0 replies; 3+ messages in thread
From: John Snow @ 2020-03-17 16:19 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: Sam Eiderman
On 3/17/20 5: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 <shmuel.eiderman@oracle.com>
> Cc: John Snow <jsnow@redhat.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> 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;
> }
>
Staged.
Trying out our gitlab CI pipelines now:
https://gitlab.com/jsnow/qemu/-/tree/ide
Traditional message:
Thanks, applied to my IDE tree:
https://github.com/jnsnow/qemu/commits/ide
https://github.com/jnsnow/qemu.git
--js
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-17 16:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-17 9:23 [PATCH] hd-geo-test: Clean up use of buf[] in create_qcow2_with_mbr() Markus Armbruster
2020-03-17 9:28 ` Philippe Mathieu-Daudé
2020-03-17 16:19 ` John Snow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).