From 44beedb8c2b4e30b421b604fb1b044402a1d1ff6 Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Sun, 9 Feb 2014 23:39:20 +0000 Subject: Fix handling of mmap failure and mapping empty files Check the return value of mmap() correctly. Empty files cannot be mmap'd so we implement some work around code for that. https://bugs.freedesktop.org/show_bug.cgi?id=74773 Signed-off-by: Stef Walter --- common/tests/test-compat.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'common/tests') diff --git a/common/tests/test-compat.c b/common/tests/test-compat.c index 872170d..42471ae 100644 --- a/common/tests/test-compat.c +++ b/common/tests/test-compat.c @@ -83,6 +83,22 @@ test_getauxval (void) free (path); } +static void +test_mmap (void) +{ + p11_mmap *map; + void *data; + size_t size; + char file[] = "emptyfileXXXXXX"; + int fd = mkstemp (file); + close (fd); + /* mmap on empty file should work */ + map = p11_mmap_open (file, NULL, &data, &size); + unlink (file); + assert_ptr_not_null (map); + p11_mmap_close (map); +} + #endif /* OS_UNIX */ int @@ -95,6 +111,7 @@ main (int argc, if (!getenv ("FAKED_MODE")) { p11_test (test_getauxval, "/compat/getauxval"); } + p11_test (test_mmap, "/compat/mmap"); #endif return p11_test_run (argc, argv); } -- cgit v1.1