Subject: | Segfault on repeated, empty mappings |
Date: | Thu, 25 Jun 2020 18:36:06 +0200 |
To: | <bug-file-map [...] rt.cpan.org> |
From: | Marc Ballarin <marc.ballarin [...] ionos.com> |
Hi,
I am observing a segfault in File::Map 0.66 on Perl 5.28/Debian Buster.
The problem does not appear in File::Map 0.64 on Perl 5.24/Debian Stretch.
The problem only occurs when attempting to map an empty file (i.e. no
actual call to mmap() is done).
To reproduce:
Create an empty file named "empty".
Run:
#!/usr/bin/perl
use strict;
use warnings;
use File::Map qw(map_file);
for (1,2) {
map_file my $data, 'empty';
}
This segfaults on the second call to maptest()/map_file() on 0.66, but
not on 0.64.
strace looks like this:
openat(AT_FDCWD, "empty", O_RDONLY|O_CLOEXEC) = 3
ioctl(3, TCGETS, 0x7ffe3c4a9080) = -1 ENOTTY (Inappropriate ioctl
for device)
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
close(3) = 0
openat(AT_FDCWD, "empty", O_RDONLY|O_CLOEXEC) = 3
ioctl(3, TCGETS, 0x7ffe3c4a9080) = -1 ENOTTY (Inappropriate ioctl
for device)
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=NULL} ---
+++ killed by SIGSEGV +++
AFAICT, your test/10-empty.t is supposed to catch this, but the test
seems buggy, as it uses $0 as file name (and $0 is not empty).
Regards,
Marc