Bug 2054 - Undef variable in Win32Locker.pm, UnixLocker.pm parens missing
Summary: Undef variable in Win32Locker.pm, UnixLocker.pm parens missing
Status: RESOLVED FIXED
Alias: None
Product: Spamassassin
Classification: Unclassified
Component: spamassassin (show other bugs)
Version: 2.55
Hardware: All All
: P3 normal
Target Milestone: 2.60
Assignee: SpamAssassin Developer Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-12 13:47 UTC by Michael Lemke
Modified: 2003-06-12 15:09 UTC (History)
0 users



Attachment Type Modified Status Actions Submitter/CLA Status
Proposed fix. patch None Michael Lemke [NoCLA]

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Lemke 2003-06-12 13:47:43 UTC
Display all headers
From:
Michael Lemke <lemkemch@t-online.de>

To:
spamassassin-
devel@lists.sourceforge.net

Date:
Thu, 12 Jun 2003 21:25:38 
+0200

Subject:
[PATCH] Bugs in Win32Locker.pm and UnixLocker.pm

While porting 
SpamAssassin to VMS I came across two bugs in
Win32Locker.pm and UnixLocker.pm.  Win32Locker 
will
access an undefined variable if the path does not exist.

Both files lack parentheses 
around the unlink call so the
warn message never works.

Here's a patch against SA 2.55.  At 
the same time I made
warnings in Win32Locker more like UnixLocker.  That way
some tests will 
succeed with Win32Locker.

Index: 
./lib/mail/spamassassin/UnixLocker.pm
===================================================================
RCS 
file: 
/cvsroot/spamassassin/spamassassin/lib/Mail/SpamAssassin/UnixLocker.pm,v
retrieving 
revision 1.2.2.5
diff -u -r1.2.2.5 UnixLocker.pm
--- 
./lib/mail/spamassassin/UnixLocker.pm       28 Mar 2003 06:41:43 -0000      1.2.2.5
+++ 
./lib/mail/spamassassin/UnixLocker.pm       12 Jun 2003 18:41:02 -0000
@@ -81,12 +81,12 @@
       # we 
got a stale lock, break it
       dbg("lock: $$ breaking stale $lock_file: age=" .
          (defined 
$lock_age ? $lock_age : "undef") . " now=$now");
-      unlink $lock_file || warn "lock: $$ unlink of 
lock file $lock_file failed: $!\n";
+      unlink ($lock_file) || warn "lock: $$ unlink of lock 
file $lock_file failed: $!\n";
     }
   }

   close(LTMP);
-  unlink $lock_tmp || warn "lock: $$ 
unlink of temp lock $lock_tmp failed: $!\n";
+  unlink ($lock_tmp) || warn "lock: $$ unlink of 
temp lock $lock_tmp failed: $!\n";

   return $is_locked;
 }
@@ -96,7 +96,7 @@
 sub 
safe_unlock {
   my ($self, $path) = @_;

-  unlink "$path.lock" || warn "unlock: $$ unlink 
failed: $path.lock\n";
+  unlink ("$path.lock") || warn "unlock: $$ unlink failed: 
$path.lock\n";
   dbg("unlock: $$ unlink $path.lock");
 }

Index: 
./lib/mail/spamassassin/Win32Locker.pm
===================================================================
RCS 
file: 
/cvsroot/spamassassin/spamassassin/lib/Mail/SpamAssassin/Win32Locker.pm,v
retrieving 
revision 1.2.2.4
diff -u -r1.2.2.4 Win32Locker.pm
--- 
./lib/mail/spamassassin/Win32Locker.pm      28 Mar 2003 06:41:43 -0000      1.2.2.4
+++ 
./lib/mail/spamassassin/Win32Locker.pm      12 Jun 2003 18:41:02 -0000
@@ -38,7 +38,7 @@

   if (-
e $lock_file && -M $lock_file > (LOCK_MAX_AGE / 86400)) {
     dbg("lock: $$ breaking stale lock: 
$lock_file");
-    unlink $lock_file;
+    unlink($lock_file) || warn "lock: $$ unlink of lock 
file $lock_file failed: $!\n";
   }
   for (my $retries = 0; $retries < $max_retries; 
$retries++) {
     if ($retries > 0) {
@@ -54,10 +54,10 @@
     # check age of lockfile ctime
     my $age = 
($#stat < 11 ? undef : $stat[10]);
     if ((!defined($age) && $retries > $max_retries / 2) ||
-       
(time - $age > LOCK_MAX_AGE))
+       (defined($age) && (time - $age > LOCK_MAX_AGE)))
     {
       
dbg("lock: $$ breaking stale lock: $lock_file");
-      unlink $lock_file;
+      
unlink($lock_file) || warn "lock: $$ unlink of lock file $lock_file failed: $!\n";
     }
   }
   
return 0;



Michael




 locker.patch
Comment 1 Michael Lemke 2003-06-12 13:54:19 UTC
Created attachment 1031 [details]
Proposed fix.
Comment 2 Theo Van Dinter 2003-06-12 14:22:46 UTC
committed.  thanks. :)
Comment 3 Michael Lemke 2003-06-12 14:46:01 UTC
Thanks for accepting it :)
But you missed one :(

A400> cvs -z3 diff -uwr 1.6 
"Win32Locker.pm
Index: 
Win32Locker.pm
===================================================================
RCS 
file: 
/cvsroot/spamassassin/spamassassin/lib/Mail/SpamAssassin/Win32Locker.pm,v
retrieving 
revision 1.6
diff -u -w -r1.6 Win32Locker.pm
--- Win32Locker.pm      12 Jun 2003 21:22:43 -0000      
1.6
+++ Win32Locker.pm      12 Jun 2003 21:44:43 -0000
@@ -68,7 +68,7 @@
 sub safe_unlock {
   my 
($self, $path) = @_;

-  unlink ("$path.lock") || warn "unlock: $$ unlink failed: 
$path.lock\n";
+  unlink "$path.lock" || warn "unlock: $$ unlink failed: $path.lock\n";
   
dbg("unlock: $$ unlink $path.lock");
 }
Comment 4 Theo Van Dinter 2003-06-12 15:08:33 UTC
Subject: Re: [SAdev]  Undef variable in Win32Locker.pm, UnixLocker.pm parens missing

On Thu, Jun 12, 2003 at 02:46:01PM -0700, bugzilla-daemon@hughes-family.org wrote:
> Thanks for accepting it :)
> But you missed one :(
> 
> -  unlink ("$path.lock") || warn "unlock: $$ unlink failed: 
> $path.lock\n";
> +  unlink "$path.lock" || warn "unlock: $$ unlink failed: $path.lock\n";

huh?  so you want to remove the parens?  you'd end up with the same problem you described.

Comment 5 Theo Van Dinter 2003-06-12 15:43:23 UTC
closing again. ;)
Comment 6 Michael Lemke 2003-06-12 23:09:30 UTC
Oops, you are right.  *I* missed one in my checked out copy.
Sorry for the confusion. Case 
solved. 
Michael