[Mimedefang] regexp (and other) problems/fixes

Rudolph Pereira rudolph at usyd.edu.au
Wed Nov 20 17:58:01 EST 2002


Hello,
I've come across a couple of problems in the mimedefang code
that I've since fixed in a local copy that I've been using for testing.
I've included the patch to the first problem (against 2.23) as I think
it's an important one, but I've also got patches (they're really
one-liners) for the others in case
they're required (and not more easily fixed some other way, or in some
later version of mimedefang). I've also
tested the included patch more throughly than the others.

The problems are:
- $1 from some regexps (e.g re_match_ext) are used without checking whether the regexp matched; if the calling function also captured something to $1 we'll
  be using that $1 blindly
- perl5.005 (default on solaris 2.8 installs) requires explicitly
  assigning to Peer in the hash - giving it one argument (e.g
  IO::Socket::UNIX->new("/blah") isn't the same as
  IO::Socket::UNIX->new(Peer=>"/blah")
  Note that I'm not actually using daemonised virus scanners at the
  moment so this hasn't been as throughly tested, but it's a one-liner
  in any case
- I had the need to alter the module include path used by the perl
  running mimedefang (i.e passing PERL="...perl -I/blah/blah1") to
  configure; this required adding some extra quoting to the Makefile so
  mimedefang would build
- configure doesn't seem to believe that Unix::Syslog is sufficient to
  do syslogging on solaris systems; it still wants Sys::Syslog to be
  installed. I really just commented out the "exit 1" at the bottom of
  the module checking loop in configure to get around this

Comments/feedback welcome.
-------------- next part --------------
diff -ru /tmp/mimedefang-2.23/mimedefang.pl.in mimedefang/mimedefang.pl.in
--- /tmp/mimedefang-2.23/mimedefang.pl.in	Thu Oct 17 17:59:48 2002
+++ mimedefang/mimedefang.pl.in	Mon Nov 11 22:40:49 2002
@@ -338,9 +338,8 @@
     my($body) = $in->bodyhandle;
     my($fname) = takeStabAtFilename($in);
     $fname = "" unless defined($fname);
-    my($extension);
-    $extension = $1 if $fname =~ /(\.[^.]*)$/;
-    $extension = "" unless defined($extension);
+    my($extension)="";
+    $extension = $1 if ($fname =~ /(\.[^.]*)$/);
 
 
     $disposition = "inline" unless defined($disposition);
@@ -1594,31 +1593,24 @@
 #***********************************************************************
 sub re_match_ext ($$) {
     my($entity, $regexp) = @_;
-    my($ext);
     my($head) = $entity->head;
 
     my($guess) = $head->mime_attr("Content-Disposition.filename");
     if (defined($guess)) {
 	$guess = decode_mimewords($guess);
-	$guess =~ /(\.[^.]*)$/;
-	$ext = $1;
-	return 1 if (defined($ext) && $ext =~ /$regexp/i);
+	return 1 if (($guess =~ /(\.[^.]*)$/) && ($1 =~ /$regexp/i));
     }
 
     $guess = $head->mime_attr("Content-Type.name");
     if (defined($guess)) {
 	$guess = decode_mimewords($guess);
-	$guess =~ /(\.[^.]*)$/;
-	$ext = $1;
-	return 1 if (defined($ext) && $ext =~ /$regexp/i);
+	return 1 if (($guess =~ /(\.[^.]*)$/) && ($1 =~ /$regexp/i));
     }
 
     $guess = $head->mime_attr("Content-Description");
     if (defined($guess)) {
 	$guess = decode_mimewords($guess);
-	$guess =~ /(\.[^.]*)$/;
-	$ext = $1;
-	return 1 if (defined($ext) && $ext =~ /$regexp/i);
+	return 1 if (($guess =~ /(\.[^.]*)$/) && ($1 =~ /$regexp/i));
     }
 
     return 0;
@@ -3845,6 +3837,7 @@
     my($ctx);
     my($path);
     my($fname, $ext, $name, $url);
+    my ($extension)="";
 
     return 0 unless defined($entity->bodyhandle);
     $path = $entity->bodyhandle->path;
@@ -3857,9 +3850,7 @@
 
     $fname = takeStabAtFilename($entity);
     $fname = "" unless defined($fname);
-    $fname =~ /(\.[^.]*)$/;
-    my($extension) = $1;
-    $extension = "" unless defined($extension);
+    $extension = $1 if ($fname =~ /(\.[^.]*)$/);
 
     # Use extension if it is .[alpha,digit,underscore]
     $extension = "" unless ($extension =~ /^\.[A-Za-z0-9_]*$/);
@@ -4250,9 +4241,8 @@
     my($body) = $in->bodyhandle;
     my($fname) = takeStabAtFilename($in);
     $fname = "" unless defined($fname);
-    $fname =~ /(\.[^.]*)$/;
-    my($extension) = $1;
-    $extension = "" unless defined($extension);
+    my($extension) = "";
+    $extension=$1 if ($fname =~ /(\.[^.]*)$/);
     $disposition = "inline" unless defined($disposition);
 
     print "    " x $level;


More information about the MIMEDefang mailing list