[PATCH 2/6] tests/qtest/migration: Initialize buffer in probe_o_direct_support

Fabiano Rosas posted 6 patches 5 months ago
[PATCH 2/6] tests/qtest/migration: Initialize buffer in probe_o_direct_support
Posted by Fabiano Rosas 5 months ago
Valgrind complains about the probe_o_direct_support() function reading
from an uninitialized buffer. For probing O_DIRECT support we don't
actually need to write to the file, just make sure the pwrite call
doesn't reject the write. Still, write zeroes to the buffer to
suppress the warning.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 tests/qtest/migration-helpers.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index 3f8ba7fa8e..981910ba35 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -496,6 +496,7 @@ bool probe_o_direct_support(const char *tmpfs)
 
     buf = qemu_try_memalign(len, len);
     g_assert(buf);
+    memset(buf, 0, len);
 
     ret = pwrite(fd, buf, len, offset);
     unlink(filename);
-- 
2.35.3
Re: [PATCH 2/6] tests/qtest/migration: Initialize buffer in probe_o_direct_support
Posted by Peter Xu 5 months ago
On Mon, Dec 09, 2024 at 05:44:23PM -0300, Fabiano Rosas wrote:
> Valgrind complains about the probe_o_direct_support() function reading
> from an uninitialized buffer. For probing O_DIRECT support we don't
> actually need to write to the file, just make sure the pwrite call
> doesn't reject the write. Still, write zeroes to the buffer to
> suppress the warning.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu
Re: [PATCH 2/6] tests/qtest/migration: Initialize buffer in probe_o_direct_support
Posted by Philippe Mathieu-Daudé 5 months ago
On 9/12/24 21:44, Fabiano Rosas wrote:
> Valgrind complains about the probe_o_direct_support() function reading
> from an uninitialized buffer. For probing O_DIRECT support we don't
> actually need to write to the file, just make sure the pwrite call
> doesn't reject the write. Still, write zeroes to the buffer to
> suppress the warning.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
>   tests/qtest/migration-helpers.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
> index 3f8ba7fa8e..981910ba35 100644
> --- a/tests/qtest/migration-helpers.c
> +++ b/tests/qtest/migration-helpers.c
> @@ -496,6 +496,7 @@ bool probe_o_direct_support(const char *tmpfs)
>   
>       buf = qemu_try_memalign(len, len);
>       g_assert(buf);

(we could directly use qemu_memalign here)

> +    memset(buf, 0, len);
>   
>       ret = pwrite(fd, buf, len, offset);
>       unlink(filename);

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>