FTNMAIL: don't die on invalid filenames master
authorSebastian <basti@notizbuch>
Tue, 30 Jun 2015 20:27:28 +0000 (22:27 +0200)
committerSebastian <basti@notizbuch>
Tue, 30 Jun 2015 20:27:28 +0000 (22:27 +0200)
modules/FTNMAIL.pm

index ac3d0a1ca0211ac820fb58866751ce05769d02bf..40e2a80f260d32fe8db4c07b808b0f143a7f3b30 100644 (file)
@@ -190,11 +190,21 @@ sub unpack_packet($)
        my $file = shift;
        my $buf, my @mails;
 
-       die("No filename!") unless($file);
-       open(PKT, '<', $file) or die("Can't open $file!\n");
+       if(!$file) {
+               LOG::warn("No filename!");
+               return;
+       }
+
+       if(!(open(PKT, '<', $file))) {
+               LOG::warn("Can't open $file!");
+               return;
+       }
        binmode(PKT);
 
-       die("Short packet!") if(read(PKT, $buf, 0x3a) != 0x3a);
+       if(read(PKT, $buf, 0x3a) != 0x3a) {
+               LOG::warn("Short packet!");
+               return;
+       }
 
        # parse packet header
        my ($onode, $dnode, $year, $month, $day, $hour, $minute, $second,
@@ -203,7 +213,10 @@ sub unpack_packet($)
                $ozone, $dzone, $opoint, $dpoint, $data) = unpack(
        "v v v v v v v v v v v v C C Z8 v v v n C C v v v v v a4", $buf);
 
-       die("Unsupported packet type $type!") unless($type == 2);
+       if($type != 2) {
+               LOG::warn("Unsupported packet type $type!");
+               return;
+       }
 
        my %packet;
        if(($cw == $cwcopy) && ($cw != 0) && ($cw & 0x0001)) {
@@ -227,17 +240,24 @@ sub unpack_packet($)
 
        # read packed messages
        while(1) {
-               die("Short packet!") if(read(PKT, $buf, 2) != 2);
+               if(read(PKT, $buf, 2) != 2) {
+                       LOG::warn("Short packet!");
+                       return;
+               }
 
                my $type = unpack("v", $buf);
                if($type == 0) {
                        close(PKT);
                        return(@mails);
                } elsif($type != 2) {
-                       die("Unsupported message type $type!");
+                       LOG::warn("Unsupported message type $type!");
+                       return;
                }
 
-               die("Short packet!") if(read(PKT, $buf, 0x20) != 0x20);
+               if(read(PKT, $buf, 0x20) != 0x20) {
+                       LOG::warn("Short packet!");
+                       return;
+               }
 
                # parse message header
                my ($tname, $fname, $subj, $text);