diff mbox series

[v1,for,3.0,2/2] tests: add check_invalid_maps to test-mmap

Message ID 20180726132947.28538-3-alex.bennee@linaro.org
State New
Headers show
Series fix for bug 1783362 | expand

Commit Message

Alex Bennée July 26, 2018, 1:29 p.m. UTC
This adds a test to make sure we fail properly for a 0 length mmap.
There are most likely other failure conditions we should also check.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Cc: umarcor <1783362@bugs.launchpad.net>
---
 tests/tcg/multiarch/test-mmap.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

-- 
2.17.1

Comments

Richard Henderson July 28, 2018, 4:45 p.m. UTC | #1
On 07/26/2018 06:29 AM, Alex Bennée wrote:
> This adds a test to make sure we fail properly for a 0 length mmap.

> There are most likely other failure conditions we should also check.

> 

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> Cc: umarcor <1783362@bugs.launchpad.net>

> ---

>  tests/tcg/multiarch/test-mmap.c | 16 +++++++++++++++-

>  1 file changed, 15 insertions(+), 1 deletion(-)


Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


Might want to test length of e.g. -4 as well, which should get ENOMEM.


r~
diff mbox series

Patch

diff --git a/tests/tcg/multiarch/test-mmap.c b/tests/tcg/multiarch/test-mmap.c
index 5c0afe6e49..7f62eba4e9 100644
--- a/tests/tcg/multiarch/test-mmap.c
+++ b/tests/tcg/multiarch/test-mmap.c
@@ -27,7 +27,7 @@ 
 #include <stdint.h>
 #include <string.h>
 #include <unistd.h>
-
+#include <errno.h>
 #include <sys/mman.h>
 
 #define D(x)
@@ -435,6 +435,19 @@  void checked_write(int fd, const void *buf, size_t count)
     fail_unless(rc == count);
 }
 
+void check_invalid_mmaps(void)
+{
+    unsigned char *addr;
+
+    /* Attempt to map a zero length page.  */
+    addr = mmap(NULL, 0, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+    fprintf(stdout, "%s addr=%p", __func__, (void *)addr);
+    fail_unless(addr == MAP_FAILED);
+    fail_unless(errno == EINVAL);
+
+    fprintf(stdout, " passed\n");
+}
+
 int main(int argc, char **argv)
 {
 	char tempname[] = "/tmp/.cmmapXXXXXX";
@@ -476,6 +489,7 @@  int main(int argc, char **argv)
 	check_file_fixed_mmaps();
 	check_file_fixed_eof_mmaps();
 	check_file_unfixed_eof_mmaps();
+	check_invalid_mmaps();
 
 	/* Fails at the moment.  */
 	/* check_aligned_anonymous_fixed_mmaps_collide_with_host(); */