send-uucp race condition with old .work temp files

Thomas Parmelan parmelan+inn at free.fr
Wed Sep 14 10:15:41 UTC 2005


When a .work temp file was left by a previous invocation, send-uucp
appends it to the current batch file BEFORE it has been flushed; this is
dangerously wrong. The following patch corrects it.

Regards,
Tom

--- send-uucp.old	2005-09-13 11:58:17.000000000 +0200
+++ send-uucp	2005-09-14 12:01:35.000000000 +0200
@@ -157,18 +157,14 @@
     $compress ||= $inn::compress;
     $size ||= $MAXSIZE;
 
-    # if exists a .work temp file left by a previous invocation, append
-    # it to the current batch file
+    # if exists a .work temp file left by a previous invocation, rename
+    # it to .work.tmp, we'll append it to the current batch file once it
+    # has been renamed and flushed.
     if (-f "$site.work") {
-        my $err = '';
-        open(OUT, ">>$site") or logdie("cannot open $site: $!");
-        open(IN, "$site.work") or logdie("cannot open $site.work: $!");
-        print OUT while <IN>;
-        close IN;
-        close OUT or logdie("cannot close $site: $!");;
+	rename("$site.work", "$site.work.tmp") or logdie("cannot rename $site.work: $!", 'crit');
     }
 
-    if (not -f $site) {
+    if (not -f $site and not -f "$site.work.tmp") {
         logmsg("no batch file for site $site", 'err');
         return;
     }
@@ -177,6 +173,17 @@
     logmsg("Flushing $funnel for site $site", 'debug');
     ctlinnd('-t120', 'flush', $funnel);
 
+    # append the old .work temp file to the current batch file if needed
+    if (-f "$site.work.tmp") {
+        my $err = '';
+        open(OUT, ">>$site.work") or logdie("cannot open $site.work: $!");
+        open(IN, "$site.work.tmp") or logdie("cannot open $site.work.tmp: $!");
+        print OUT while <IN>;
+        close IN;
+        close OUT or logdie("cannot close $site.work: $!");;
+	unlink "$site.work.tmp" or logmsg("cannot delete $site.work.tmp: $!", 'err');
+    }
+
     if (not -s "$site.work") {
         logmsg("no articles for $site", 'debug');
         unlink "$site.work" or logmsg("cannot delete $site.work: $!", 'err');

-- 
Thomas Parmelan  -+-  tom at ankh.fr.EU.org


More information about the inn-workers mailing list