diff options
author | Jens Schanz <mail@jensschanz.de> | 2020-04-27 16:45:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-27 16:45:38 +0300 |
commit | 0c0ae92bd6f34efeab56b4e06b05850ac4d5c82f (patch) | |
tree | bb84050e12031023f7726119faf0235ce8432821 | |
parent | bb5dd8b6f84ab6ee04b2e7f9d3bba07165735eea (diff) |
validate policy_published element in xml
check policy_published element for hash to avoid an error if report is broken
fixes
```
Not a HASH reference at dmarcts-report-parser.pl line 721.
```
-rwxr-xr-x | dmarcts-report-parser.pl | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/dmarcts-report-parser.pl b/dmarcts-report-parser.pl index 410a196..a8f4072 100755 --- a/dmarcts-report-parser.pl +++ b/dmarcts-report-parser.pl @@ -717,12 +717,28 @@ sub storeXMLInDatabase { my $id = $xml->{'report_metadata'}->{'report_id'}; my $email = $xml->{'report_metadata'}->{'email'}; my $extra = $xml->{'report_metadata'}->{'extra_contact_info'}; - my $domain = $xml->{'policy_published'}->{'domain'}; - my $policy_adkim = $xml->{'policy_published'}->{'adkim'}; - my $policy_aspf = $xml->{'policy_published'}->{'aspf'}; - my $policy_p = $xml->{'policy_published'}->{'p'}; - my $policy_sp = $xml->{'policy_published'}->{'sp'}; - my $policy_pct = $xml->{'policy_published'}->{'pct'}; + my $domain = undef; + my $policy_adkim = undef; + my $policy_aspf = undef; + my $policy_p = undef; + my $policy_sp = undef; + my $policy_pct = undef; + + if (ref $xml->{'policy_published'} eq "HASH") { + $domain = $xml->{'policy_published'}->{'domain'}; + $policy_adkim = $xml->{'policy_published'}->{'adkim'}; + $policy_aspf = $xml->{'policy_published'}->{'aspf'}; + $policy_p = $xml->{'policy_published'}->{'p'}; + $policy_sp = $xml->{'policy_published'}->{'sp'}; + $policy_pct = $xml->{'policy_published'}->{'pct'}; + } else { + $domain = $xml->{'policy_published'}[0]->{'domain'}; + $policy_adkim = $xml->{'policy_published'}[0]->{'adkim'}; + $policy_aspf = $xml->{'policy_published'}[0]->{'aspf'}; + $policy_p = $xml->{'policy_published'}[0]->{'p'}; + $policy_sp = $xml->{'policy_published'}[0]->{'sp'}; + $policy_pct = $xml->{'policy_published'}[0]->{'pct'}; + } # see if already stored my $sth = $dbh->prepare(qq{SELECT org, serial FROM report WHERE reportid=?}); |