78f1eb
From 7c3f362035dec9b7eaec388b1f7f1619c1bd96a3 Mon Sep 17 00:00:00 2001
78f1eb
From: Tony Cook <tony@develop-help.com>
78f1eb
Date: Mon, 4 Nov 2019 09:52:22 +1100
78f1eb
Subject: [PATCH] prevent a race between name-based stat and an open modifying
78f1eb
 atime
78f1eb
MIME-Version: 1.0
78f1eb
Content-Type: text/plain; charset=UTF-8
78f1eb
Content-Transfer-Encoding: 8bit
78f1eb
78f1eb
Most linux systems rarely update atime, so it's very unlikely
78f1eb
for this issue to trigger there, but on a system with classic atime
78f1eb
behaviour this was a race between open modifying atime and time()
78f1eb
ticking over.
78f1eb
78f1eb
gh #17234
78f1eb
78f1eb
Signed-off-by: Petr Písař <ppisar@redhat.com>
78f1eb
---
78f1eb
 lib/File/stat.t | 6 ++++--
78f1eb
 1 file changed, 4 insertions(+), 2 deletions(-)
78f1eb
78f1eb
diff --git a/lib/File/stat.t b/lib/File/stat.t
78f1eb
index c403fc4498..fc9bb12cef 100644
78f1eb
--- a/lib/File/stat.t
78f1eb
+++ b/lib/File/stat.t
78f1eb
@@ -133,6 +133,9 @@ SKIP: {
78f1eb
     test_X_ops($^X, "for $^X", qr/A/);
78f1eb
 }
78f1eb
 
78f1eb
+# open early so atime is consistent with the name based call
78f1eb
+local *STAT;
78f1eb
+my $canopen = open(STAT, '<', $file);
78f1eb
 
78f1eb
 my $stat = File::stat::stat($file);
78f1eb
 isa_ok($stat, 'File::stat', 'should build a stat object');
78f1eb
@@ -143,8 +146,7 @@ for (split //, "tTB") {
78f1eb
 }
78f1eb
 
78f1eb
 SKIP: {
78f1eb
-	local *STAT;
78f1eb
-	skip("Could not open file: $!", 2) unless open(STAT, '<', $file);
78f1eb
+	skip("Could not open file: $!", 2) unless $canopen;
78f1eb
 	isa_ok(File::stat::stat('STAT'), 'File::stat',
78f1eb
 	       '... should be able to find filehandle');
78f1eb
 
78f1eb
-- 
78f1eb
2.21.0
78f1eb