This simple module audits your perl and looks for all non-literal sprintf/printf formats. They might be vunerable to an overflow bug in perls less than 5.8.8.
I haven't had a chance to try this out yet but thought I'd just post it and amend later if and when I find bugs.
See Searching for sprintf() bug exploit opportunities in core and CPAN modules for some results after I started auditing my local code using this module.
package SprintfBugChecker; use B 'OPf_STACKED'; use B::Utils qw( walkallops_filtered opgrep carp ); CHECK { check() } sub check { walkallops_filtered( \&is_non_literal_sprintf_format, \&report_non_literal_sprintf_format ); return; } sub is_non_literal_sprintf_format { no warnings; my $op = shift; my $name = eval { $op->oldname }; if ( $name eq 'sprintf' ) { return opgrep( { first => { sibling => { name => [qw[! const]] + } } }, $op ); } elsif ( $name eq 'prtf' ) { if ( $op->flags & OPf_STACKED ) { return opgrep( { first => { sibling => { sibling => { name => [qw[! const] +] } } } }, $op ); } else { return opgrep( { first => { sibling => { name => [qw[! const]] } } }, + $op ); } } return; } sub report_non_literal_sprintf_format { warn( "Danger! Danger Will Robinson! at $B::Utils::file line $B::Uti +ls::line.\n" ); return; } "Ye olde true value."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Experimental sprintf overflow bug detector
by jkva (Chaplain) on Dec 02, 2005 at 10:56 UTC | |
|
Re: Experimental sprintf overflow bug detector
by dragonchild (Archbishop) on Dec 02, 2005 at 03:39 UTC | |
by diotalevi (Canon) on Dec 02, 2005 at 06:37 UTC |