[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.12-2-gdcca7a7



The following commit has been merged in the master branch:
commit dcca7a7917722916b311783dba666be73f9c5729
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Apr 19 09:01:17 2013 +0200

    L::Util::touch_file: Pass the filehandle to utime
    
    Pass the open filehandle to utime instead of the file name.  This
    ensures that we change the utime of the "correct" file (i.e. we avoid
    a possible race condition).
    
    The race condition could not occur with Lintian current use of this
    sub, but that might change and others might use the code as reference.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/debian/changelog b/debian/changelog
index 2978945..80dbb7a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,9 @@ lintian (2.5.13) UNRELEASED; urgency=low
       distribution.  Thanks to Romain Francoise for the
       report and the patch.  (Closes: #705170)
 
+  * lib/Lintian/Util.pm:
+    + [NT] Fix a race condition in touch_file.
+
  -- Niels Thykier <niels@thykier.net>  Tue, 16 Apr 2013 18:24:45 +0200
 
 lintian (2.5.12) experimental; urgency=medium
diff --git a/lib/Lintian/Util.pm b/lib/Lintian/Util.pm
index 59f9171..064be40 100644
--- a/lib/Lintian/Util.pm
+++ b/lib/Lintian/Util.pm
@@ -949,7 +949,7 @@ sub __open_gz_ext {
     return $fd;
 }
 
-=item touch_File (FILE)
+=item touch_file(FILE)
 
 Updates the "mtime" of FILE.  If FILE does not exist, it will be
 created.
@@ -964,12 +964,19 @@ sub touch_file {
     # We use '>>' because '>' truncates the file if it has contents
     # (which `touch file` doesn't).
     open my $fd, '>>', $file or return 0;
-    close $fd or return 0;
+
     # open with '>>' does not update the mtime if the file already
     # exists, so use utime to solve that.
-    utime undef, undef, $file or return 0;
+    if (!utime(undef, undef, $fd)) {
+        # utime failed.  Preserve the utime error in $! and
+        # always return 0
+        local $! = 0;
+        close($fd);
+        return 0;
+    }
 
-    return 1;
+    # utime succeeded, then close decides the return code (and $!).
+    return close($fd);
 }
 
 =item fail (MSG[, ...])

-- 
Debian package checker


Reply to: