Subject: | negative offset segv |
Date: | Fri, 16 Apr 2010 10:06:27 +1000 |
To: | bug-File-Map [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
With 0.24 a small negative offset like
map_file (my $str, '/etc/motd', '<', -1, 100);
print $str,"\n";
=> segv
succeeds in the map_file and then segfaults printing the string, where I
expected it to fail with EINVAL the same as a large negative does,
map_file (my $str, '/etc/motd', '<', -9999, 100);
=> EINVAL
I think the page-boundary "correction" value goes negative if the input
is negative, which I think rounds the wrong way. Eg. offset==-1
length==100 becomes offset==0 length==99 or something like that, where
it probably should be offset==-4096 length==4195 of some such.
It's probably both easiest and best to let negatives go through to the
system call, so it can give whatever the usual system error is for such
nonsense -- but take care not to turn negative into non-negative by the
pagesize rounding :-).