[PATCH] tests/tcg/i386/test-flags: Check mmap() return value

longlong yan posted 1 patch 3 weeks, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260630060429.588-1-yanlonglong@kylinos.cn
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>
tests/tcg/i386/test-flags.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] tests/tcg/i386/test-flags: Check mmap() return value
Posted by longlong yan 3 weeks, 5 days ago
test-flags.c calls mmap() to allocate a page but does not check
whether it succeeded.  If the allocation fails, the following
*mprotect()* and *asm* block dereference the invalid pointer and
produce a confusing failure.

Add an assertion to fail early with a clear message.

Fixes: e7bbb7cb71b3 ("target/i386: introduce flags writeback mechanism")
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
 tests/tcg/i386/test-flags.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/tcg/i386/test-flags.c b/tests/tcg/i386/test-flags.c
index c379e29627..4ecf7053e2 100644
--- a/tests/tcg/i386/test-flags.c
+++ b/tests/tcg/i386/test-flags.c
@@ -21,6 +21,7 @@ int main()
 
     /* fault in the page then protect it */
     addr = mmap (NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+    assert(addr != MAP_FAILED);
     *addr = 0x1234;
     mprotect(addr, 4096, PROT_READ);
 
-- 
2.43.0