Created attachment 93744 [details] [review] Fix the tested value mmap man page: On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set appropriately. Code in p11_mmap_open: map->data = mmap (NULL, map->size, PROT_READ, MAP_PRIVATE, map->fd, 0); if (map->data == NULL) { close (map->fd); free (map); return NULL; } *data = map->data; *size = map->size; return map; map->data will never be NULL, it will be either an address or -1.
Also, to see the problem, you can create an empty conf file as mmap on an empty file fails.
Created attachment 93879 [details] [review] Add a test Strace of the test: [pid 13017] open("emptyfileU0ly3U", O_RDWR|O_CREAT|O_EXCL, 0600) = 3 [pid 13017] close(3) = 0 [pid 13017] open("emptyfileU0ly3U", O_RDONLY|O_CLOEXEC) = 3 [pid 13017] fstat(3, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0 [pid 13017] mmap(NULL, 0, PROT_READ, MAP_PRIVATE, 3, 0) = -1 EINVAL (Invalid argument) [pid 13017] close(3) = 0 [pid 13017] unlink("emptyfileU0ly3U") = 0
*** Bug 74904 has been marked as a duplicate of this bug. ***
Created attachment 93989 [details] [review] Fix handling of mmap failure and mapping empty files Thanks for the patch and test. I've updated the patch to include support for mapping empty files. https://bugs.freedesktop.org/show_bug.cgi?id=74773 Signed-off-by: Stef Walter <stef@thewalter.net>
Attachment 93989 [details] pushed as 44beedb - Fix handling of mmap failure and mapping empty files
Pushed a similar patch to stable branch.
Thanks, even better like that :)
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.