Skip Menu |

This queue is for tickets about the File-Map CPAN distribution.

Report information
The Basics
Id: 68787
Status: resolved
Priority: 0/
Queue: File-Map

People
Owner: LEONT [...] cpan.org
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: mmap and taint mode
Date: Mon, 13 Jun 2011 11:56:22 +1000
To: bug-File-Map [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Under "perl -T" anything read from a file with plain I/O is tainted. Might the same be applied to mmapped file scalars? I don't know very much about how well taint works in practice, but I thought in my file iterator stuff to have the same taintedness come out whether using read() or mmap(). Having it automatically propagate out of an mmapped scalar would seem good. -- I played a country and western song backwards to listen for evil messages. It sounded just the same except it was about a fella whose wife stood by him while he got in a successful harvest and his dog recovered from illness.
On Sun Jun 12 21:57:23 2011, user42@zip.com.au wrote: Show quoted text
> Under "perl -T" anything read from a file with plain I/O is tainted. > Might the same be applied to mmapped file scalars? > > I don't know very much about how well taint works in practice, but I > thought in my file iterator stuff to have the same taintedness come out > whether using read() or mmap(). Having it automatically propagate out > of an mmapped scalar would seem good.
Hi Kevin, Good catch. It seems simple enough to fix, but I'm rather lacking time right now. Could you write some tests? Then I'll implement the fix. Leon
Subject: Re: [rt.cpan.org #68787] mmap and taint mode
Date: Sat, 25 Jun 2011 10:23:18 +1000
To: bug-File-Map [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Leon Timmermans via RT" <bug-File-Map@rt.cpan.org> writes: Show quoted text
> > It seems simple enough to fix, but I'm rather lacking time > right now.
I tried tainting the target scalar before mmapping into it and that worked, but tainting afterwards didn't. Dunno what that means. The only thing maybe needing might be to ensure an mmap of an empty file is tainted too. A read() of zero bytes taints its output, presumably on the basis that the absence of content from a file affects a program's output the same as actual bytes from it -- the usual most-conservative view of tainting ... Show quoted text
> tests?
If it helps, in my code I've tried to have Taint::Util tainted() say the same thing on a file read() as on data coming out of my manipulations, skipping the tests if that module not available, so vaguely eval { require Taint::Util; 1 } or plan skip_all => "due to Taint::Util not available -- $@"; my $want_taint; { open my $fh, '<', $filename or die "Oops, cannot open $filename"; my $bytes; read($fh, $bytes, 1) or die "Oops, cannot read $filename"; close $fh or die "Oops, error closing $filename"; $want_taint = Taint::Util::tainted($bytes); } my $entry = $it->next; my $got_taint = Taint::Util::tainted($entry); is ($got_taint, $want_taint, "tainted() on ..."); which might be adapted to say that after map_file or map_handle the taintedness of the mapped scalar should be the same as the $want_taint. I think tests have to be exercised as HARNESS_PERL_SWITCHES="-T" make test since the -T has to be on the actual command line.
On Sun Jun 12 21:57:23 2011, user42@zip.com.au wrote: Show quoted text
> Under "perl -T" anything read from a file with plain I/O is tainted. > Might the same be applied to mmapped file scalars? > > I don't know very much about how well taint works in practice, but I > thought in my file iterator stuff to have the same taintedness come out > whether using read() or mmap(). Having it automatically propagate out > of an mmapped scalar would seem good.
I've just released File::Map 0.38, which includes a fix for this :-) Leon