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