fix for intermitent matching issues when processing found keys

This commit is contained in:
Zane C. B-H 2022-12-17 14:31:16 -06:00
parent 3bd1b1c936
commit 402dc52dc3
4 changed files with 49 additions and 39 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
bin/regexp-f2b
!Build/
.last_cover_stats
/META.yml

View File

@ -4,42 +4,47 @@ use warnings;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
NAME => 'Regexp::F2B',
AUTHOR => q{Zane C. Bowers-Hadley <vvelox@vvelox.net>},
VERSION_FROM => 'lib/Regexp/F2B.pm',
ABSTRACT_FROM => 'lib/Regexp/F2B.pm',
LICENSE => 'gpl_2',
MIN_PERL_VERSION => '5.006',
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => '0',
},
TEST_REQUIRES => {
'Test::More' => '0',
},
PREREQ_PM => {
#'ABC' => '1.6',
#'Foo::Bar::Module' => '5.0401',
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Regexp-F2B-*' },
NAME => 'Regexp::F2B',
AUTHOR => q{Zane C. Bowers-Hadley <vvelox@vvelox.net>},
VERSION_FROM => 'lib/Regexp/F2B.pm',
ABSTRACT_FROM => 'lib/Regexp/F2B.pm',
LICENSE => 'gpl_2',
MIN_PERL_VERSION => '5.006',
INST_SCRIPT => 'bin',
EXE_FILES => ['src_bin/regexp-f2b'],
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => '0',
},
TEST_REQUIRES => {
'Test::More' => '0',
},
PREREQ_PM => {
'Data::Dumper' => '0',
'File::Slurp' => '0',
'File::Spec' => '0',
'Regexp::IPv4' => '0',
'Regexp::IPv6' => '0',
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Regexp-F2B-*' },
);
# Compatibility with old versions of ExtUtils::MakeMaker
unless (eval { ExtUtils::MakeMaker->VERSION('6.64'); 1 }) {
my $test_requires = delete $WriteMakefileArgs{TEST_REQUIRES} || {};
@{$WriteMakefileArgs{PREREQ_PM}}{keys %$test_requires} = values %$test_requires;
unless ( eval { ExtUtils::MakeMaker->VERSION('6.64'); 1 } ) {
my $test_requires = delete $WriteMakefileArgs{TEST_REQUIRES} || {};
@{ $WriteMakefileArgs{PREREQ_PM} }{ keys %$test_requires } = values %$test_requires;
}
unless (eval { ExtUtils::MakeMaker->VERSION('6.55_03'); 1 }) {
my $build_requires = delete $WriteMakefileArgs{BUILD_REQUIRES} || {};
@{$WriteMakefileArgs{PREREQ_PM}}{keys %$build_requires} = values %$build_requires;
unless ( eval { ExtUtils::MakeMaker->VERSION('6.55_03'); 1 } ) {
my $build_requires = delete $WriteMakefileArgs{BUILD_REQUIRES} || {};
@{ $WriteMakefileArgs{PREREQ_PM} }{ keys %$build_requires } = values %$build_requires;
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION('6.52'); 1 };
unless eval { ExtUtils::MakeMaker->VERSION('6.52'); 1 };
delete $WriteMakefileArgs{MIN_PERL_VERSION}
unless eval { ExtUtils::MakeMaker->VERSION('6.48'); 1 };
unless eval { ExtUtils::MakeMaker->VERSION('6.48'); 1 };
delete $WriteMakefileArgs{LICENSE}
unless eval { ExtUtils::MakeMaker->VERSION('6.31'); 1 };
unless eval { ExtUtils::MakeMaker->VERSION('6.31'); 1 };
WriteMakefile(%WriteMakefileArgs);

View File

@ -584,20 +584,24 @@ sub proc_line {
return $found;
}
#
# now search through each regexp for possible matches
#
$int = 0;
$not_found = 1;
while ( defined( $self->{regexp}[$int] ) && $not_found ) {
# copy this here so the key test for F keys does not cause an issue
my $regexp = $self->{regexp}[$int];
if ( $joined =~ /$regexp/ ) {
foreach my $key ( keys(%+) ) {
my $val=$+{$key};
my %found_items=%+;
foreach my $key ( keys(%found_items) ) {
$not_found = 0;
if ($key=~/^F/) {
my $new_key=$key;
$new_key=~s/^F/F-/;
$found->{$new_key} = $val;
$found->{$new_key} = $found_items{$key};
}else {
$found->{$key} = $val;
$found->{$key} = $found_items{$key};
}
}
$not_found = 0;

View File

@ -281,10 +281,10 @@ $tests_ran++;
eval {
$object = Regexp::F2B->new(
pre_regexp =>
['^\d\d\d\d\-\d\d\-\d\dT\d\d\:\d\d:\d\d\ <F-MLFID>\w\w*\[\d\d*\]</F-MLFID>\: <F-CONTENT>.*</F-CONTENT>$'],
regexp => ['auth failed src: <HOST>, dst:<F-DEST>..*</F-DEST>$']
['^\d\d\d\d\-\d\d\-\d\dT\d\d\:\d\d:\d\d\ <F-MLFID>\w\w*\[\d\d*\]</F-MLFID>\: <F-CONTENT>.*</F-CONTENT>$'],
regexp => ['auth failed src: <HOST>, dst: <F-DEST>..*</F-DEST>$']
);
my $line = '2022-09-11T05:03:11 sshd[1234]: auth failed src: ::1, dst:5.6.7.8';
my $line = '2022-09-11T05:03:11 sshd[1234]: auth failed src: ::1, dst: 5.6.7.8';
my $matched;
eval { $matched = $object->proc_line($line); };
if ($@) {
@ -292,16 +292,16 @@ eval {
'$object->proc_line($line) died... line=' . Dumper($line) . "\nobject=" . Dumper($object) . "\n\$@=" . $@ );
}
if ( $matched->{HOST} ne '::1' ) {
die( "returned '" . Dumper($matched) . "'\n\n" . Dumper( $line, $object ) );
die( "HOST match error... returned '" . Dumper($matched) . "'\n\n" . Dumper( $line, $object ) );
}
if ( $matched->{'F-MLFID'} ne 'sshd[1234]' ) {
die( "returned '" . Dumper($matched) . "'\n\n" . Dumper( $line, $object ) );
die( "F-MLFID match error... returned '" . Dumper($matched) . "'\n\n" . Dumper( $line, $object ) );
}
if ( $matched->{'F-CONTENT'} ne 'auth failed src: ::1, dst:5.6.7.8' ) {
die( "returned '" . Dumper($matched) . "'\n\n" . Dumper( $line, $object ) );
if ( $matched->{'F-CONTENT'} ne 'auth failed src: ::1, dst: 5.6.7.8' ) {
die( "F-CONTENT match error... returned '" . Dumper($matched) . "'\n\n" . Dumper( $line, $object ) );
}
if ( $matched->{'F-DEST'} ne '5.6.7.8' ) {
die( "returned '" . Dumper($matched) . "'\n\n" . Dumper( $line, $object ) );
die( "F-DEST match error... returned '" . Dumper($matched) . "'\n\n" . Dumper( $line, $object ) );
}
$worked = 1;
};