From b663dee14ae97dd1480936bb5a7df147f85064fd Mon Sep 17 00:00:00 2001 From: Wolfgang Karall-Ahlborn Date: Wed, 17 Mar 2021 20:00:13 +0100 Subject: Reduce chances of getting a 'mystery' result Handle seen-in-the-wild cases of - no at all - empty Also use 'return' instead of 'next' for leaving dorow(). --- dmarcts-report-parser.pl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dmarcts-report-parser.pl b/dmarcts-report-parser.pl index dffd41f..9136d24 100755 --- a/dmarcts-report-parser.pl +++ b/dmarcts-report-parser.pl @@ -758,6 +758,12 @@ sub storeXMLInDatabase { $policy_pct = $xml->{'policy_published'}[0]->{'pct'}; } + my $record = $xml->{'record'}; + if ( ! defined($record) ) { + warn "$scriptname: $org: $id: No records in report. Skipped.\n"; + return 0; + } + # begin transaction if ($db_tx_support) { $dbh->do(qq{START TRANSACTION}); @@ -819,13 +825,15 @@ sub storeXMLInDatabase { if ($debug){ print " serial $serial \n"; } - my $record = $xml->{'record'}; sub dorow($$$$) { my ($serial,$recp,$org,$id) = @_; my %r = %$recp; my $ip = $r{'row'}->{'source_ip'}; - #print "ip $ip\n"; + if ( $ip eq '' ) { + warn "$scriptname: $org: $id: source_ip is empty. Skipped.\n"; + return 0; + } my $count = $r{'row'}->{'count'}; my $disp = $r{'row'}->{'policy_evaluated'}->{'disposition'}; # some reports don't have dkim/spf, "unknown" is default for these @@ -928,7 +936,7 @@ sub storeXMLInDatabase { $iptype = "ip6"; } else { warn "$scriptname: $org: $id: ??? mystery ip $ip\n"; - next; # of dorow + return 0; } $dbh->do(qq{INSERT INTO rptrecord(serial,$iptype,rcount,disposition,spf_align,dkim_align,reason,dkimdomain,dkimresult,spfdomain,spfresult,identifier_hfrom) -- cgit v1.2.3