diff options
author | TechSneeze <dave@techsneeze.com> | 2021-04-03 19:18:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-03 19:18:25 +0300 |
commit | e07bb49f9630e982c26eedf0f26a654d660b3bea (patch) | |
tree | 8c643f1156e2f281ee1cee58c0638c6336dc3f74 | |
parent | e83fe26cb1ebc823a3b641daa9b8f5e18c13798f (diff) | |
parent | eb45c1bd5bd41ec4b62b649db4900f16ce868a19 (diff) |
Merge pull request #97 from wolfgangkarall/safe_open
Use 3+ argument open() calls, as we're not dealing with 'known literals'
-rwxr-xr-x | dmarcts-report-parser.pl | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/dmarcts-report-parser.pl b/dmarcts-report-parser.pl index c33f655..6c4264a 100755 --- a/dmarcts-report-parser.pl +++ b/dmarcts-report-parser.pl @@ -410,7 +410,7 @@ if ($reports_source == TS_IMAP) { unlink($f); } $counts++; - } elsif (open FILE, $f) { + } elsif (open(FILE, "<", $f)) { $filecontent = join("", <FILE>); close FILE; @@ -643,7 +643,7 @@ sub getXMLFromMessage { open(XML, "<:gzip", $location) or $unzip = "ungzip"; } else { - open(XML,"unzip -p " . $location . " |") + open(XML, "-|", "unzip", "-p", $location) or $unzip = "unzip"; # Will never happen. # Sadly unzip -p never failes, but we can check if the @@ -651,7 +651,6 @@ sub getXMLFromMessage { # not open/failed. if (eof XML) { $unzip = "unzip"; - close XML; } } @@ -666,6 +665,7 @@ sub getXMLFromMessage { } else { warn "$scriptname: Subject: $subj\n:"; warn "$scriptname: Failed to $unzip ZIP file (temp. location: <$location>)! \n"; + close XML; } } else { warn "$scriptname: Subject: $subj\n:"; @@ -683,10 +683,8 @@ sub getXMLFromZip { my $filename = $_[0]; my $mtype = mimetype($filename); - if (open FILE, $filename) { - if ($debug) { - print "Filename: $filename, MimeType: $mtype\n"; - } + if ($debug) { + print "Filename: $filename, MimeType: $mtype\n"; } my $isgzip = 0; @@ -716,7 +714,7 @@ sub getXMLFromZip { open(XML, "<:gzip", $filename) or $unzip = "ungzip"; } else { - open(XML,"unzip -p " . $filename . " |") + open(XML, "-|", "unzip", "-p", $filename) or $unzip = "unzip"; # Will never happen. # Sadly unzip -p never failes, but we can check if the @@ -724,7 +722,6 @@ sub getXMLFromZip { # not open/failed. if (eof XML) { $unzip = "unzip"; - close XML; } } @@ -737,6 +734,7 @@ sub getXMLFromZip { close XML; } else { warn "$scriptname: Failed to $unzip ZIP file (<$filename>)! \n"; + close XML; } } else { warn "$scriptname: Could not find an <$filename>! \n"; |