Skip to content

Commit

Permalink
Use Perl 5.10+ 'state' to statically compile a regex
Browse files Browse the repository at this point in the history
Optimize get_ips() since it's called a lot
  • Loading branch information
Sullo committed Oct 30, 2024
1 parent 277a630 commit b8f7252
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions program/plugins/nikto_core.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -2744,12 +2744,9 @@ sub set_scan_items {
#######################################################################
# extract IP like strings and return an array
sub get_ips {
my $string = $_[0] || return;
my @ips;
while ($string =~ /(?:\b|[^0-9v])($LW2::IPv4_re|$LW2::IPv6_re_inc_zoneid)(?:\b|[^0-9])/g) {
push(@ips, $1);
}
return @ips;
my $string =shift || return;
state $ip_regex = qr/(?:\b|[^0-9v])($LW2::IPv4_re|$LW2::IPv6_re_inc_zoneid)(?:\b|[^0-9])/;
return $string =~ /$ip_regex/g;
}

#######################################################################
Expand Down

0 comments on commit b8f7252

Please sign in to comment.