You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/12/28 14:14:07 UTC
svn commit: r607235 - in /spamassassin/branches/3.2/lib/Mail/SpamAssassin:
BayesStore/DBM.pm DBBasedAddrList.pm Util.pm
Author: jm
Date: Fri Dec 28 05:14:06 2007
New Revision: 607235
URL: http://svn.apache.org/viewvc?rev=607235&view=rev
Log:
bug 5612: DB_File version 4.2.x has a bug that loops infinitely if files named '__db.{filename}' are present; work around. thanks to J. Nick Koston for the report and fix
Modified:
spamassassin/branches/3.2/lib/Mail/SpamAssassin/BayesStore/DBM.pm
spamassassin/branches/3.2/lib/Mail/SpamAssassin/DBBasedAddrList.pm
spamassassin/branches/3.2/lib/Mail/SpamAssassin/Util.pm
Modified: spamassassin/branches/3.2/lib/Mail/SpamAssassin/BayesStore/DBM.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/lib/Mail/SpamAssassin/BayesStore/DBM.pm?rev=607235&r1=607234&r2=607235&view=diff
==============================================================================
--- spamassassin/branches/3.2/lib/Mail/SpamAssassin/BayesStore/DBM.pm (original)
+++ spamassassin/branches/3.2/lib/Mail/SpamAssassin/BayesStore/DBM.pm Fri Dec 28 05:14:06 2007
@@ -279,7 +279,11 @@
my $name = $path.'_'.$dbname;
my $db_var = 'db_'.$dbname;
dbg("bayes: tie-ing to DB file R/W $name");
- tie %{$self->{$db_var}},$self->DBM_MODULE,$name, O_RDWR|O_CREAT,
+
+ ($self->DBM_MODULE eq 'DB_File') and
+ Mail::SpamAssassin::Util::avoid_db_file_locking_bug ($name);
+
+ tie %{$self->{$db_var}},$self->DBM_MODULE, $name, O_RDWR|O_CREAT,
(oct($main->{conf}->{bayes_file_mode}) & 0666)
or goto failed_to_tie;
}
Modified: spamassassin/branches/3.2/lib/Mail/SpamAssassin/DBBasedAddrList.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/lib/Mail/SpamAssassin/DBBasedAddrList.pm?rev=607235&r1=607234&r2=607235&view=diff
==============================================================================
--- spamassassin/branches/3.2/lib/Mail/SpamAssassin/DBBasedAddrList.pm (original)
+++ spamassassin/branches/3.2/lib/Mail/SpamAssassin/DBBasedAddrList.pm Fri Dec 28 05:14:06 2007
@@ -82,15 +82,19 @@
dbg("auto-whitelist: tie-ing to DB file of type $dbm_module $mod1 in $path");
+ ($self->{is_locked} && $dbm_module eq 'DB_File') and
+ Mail::SpamAssassin::Util::avoid_db_file_locking_bug ($path);
+
if (! tie %{ $self->{accum} }, $dbm_module, $path, $mod2,
- oct($main->{conf}->{auto_whitelist_file_mode}) ) {
- my $err = $!; # might get overwritten later
- if ($self->{is_locked}) {
- $self->{main}->{locker}->safe_unlock($self->{locked_file});
- $self->{is_locked} = 0;
- }
- die "auto-whitelist: cannot open auto_whitelist_path $path: $err\n";
+ oct($main->{conf}->{auto_whitelist_file_mode}) )
+ {
+ my $err = $!; # might get overwritten later
+ if ($self->{is_locked}) {
+ $self->{main}->{locker}->safe_unlock($self->{locked_file});
+ $self->{is_locked} = 0;
}
+ die "auto-whitelist: cannot open auto_whitelist_path $path: $err\n";
+ }
}
bless ($self, $class);
Modified: spamassassin/branches/3.2/lib/Mail/SpamAssassin/Util.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/lib/Mail/SpamAssassin/Util.pm?rev=607235&r1=607234&r2=607235&view=diff
==============================================================================
--- spamassassin/branches/3.2/lib/Mail/SpamAssassin/Util.pm (original)
+++ spamassassin/branches/3.2/lib/Mail/SpamAssassin/Util.pm Fri Dec 28 05:14:06 2007
@@ -57,6 +57,7 @@
use Config;
use File::Spec;
+use File::Basename;
use Time::Local;
use Sys::Hostname (); # don't import hostname() into this namespace!
use Fcntl;
@@ -1547,6 +1548,32 @@
$lang ||= $ENV{'LANG'};
push (@locales, $lang) if defined($lang);
return @locales;
+}
+
+###########################################################################
+
+# bug 5612: work around for bugs in Berkeley db 4.2
+#
+# on 4.2 having the __db.[DBNAME] file will cause an loop that will never finish
+# on 4.3+ the loop will timeout after 301 open attempts, but we will still
+# be unable to open the database. This workaround solves both problems.
+#
+sub avoid_db_file_locking_bug {
+ my ($path) = @_;
+
+ my $db_tmpfile = untaint_file_path(File::Spec->catfile(dirname($path),
+ '__db.'.basename($path)));
+
+ # delete "__db.[DBNAME]" and "__db.[DBNAME].*"
+ foreach my $tfile ($db_tmpfile, <$db_tmpfile.*>) {
+ my $file = untaint_file_path($tfile);
+ next unless (-e $file);
+
+ dbg("Berkeley DB bug work-around: cleaning tmp file $file");
+ if (!unlink($file)) {
+ die "cannot remove Berkeley DB tmp file $file: $!\n";
+ }
+ }
}
###########################################################################