note
diotalevi
<p>This is a short scratch list of easily implementable ideas for defending against readline(*ARGV). The ultimate form would be a module which when loaded subsequently "fixes" everything else. I'm imagining it could be used like <code>perl -MSafeARGV -ne '...'</code>. This "fix" should have no effect any future fixing of this behaviour in the actual codebase.</p><h4>Idea #0</h4><p>die("Unsafe readline(*ARGV)") when readline(*ARGV) is detected:</p><code>$ perl -MO=Concise -e 'print <>'
7 <@> leave[t1] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
6 <@> print vK ->7
3 <0> pushmark s ->4
5 <1> readline[t1] lK/1 ->6
4 <$> gv(*ARGV) s ->5 *ARGV</code><h4>Idea #1</h4><p>Override readline() and pass the filenames to sysopen() instead. Or detect GvNAME for the passed in filehandle and die("Unsafe readline(*ARGV)") if *ARGV is detected.</p><code>package SafeReadline;
require Exporter;
@ISA = 'Exporter';
@EXPORT = 'readline';
sub import {
my $pkg = shift;
return unless @_;
my $sym = shift;
$pkg->export("CORE::GLOBAL", $sym, @_);
}
sub readline { ... }</code><h4>Idea #2</h4><p>Alter the optree so that to get the effect of overriding readline() without actually doing that. This would get around the nullifying effects of multiple readline() overriding modules. Ok, this is harder, would require some tuits, and leaves anything less than 5.8.0 out in the cold ([cpan://B::Generate] is only for 5.8.0 and above).</p><hr />
258980
258980