perl/perl-5.31.5-prevent-a-race-between-name-based-stat-and-an-open-m.patch
2023-05-05 22:13:53 +02:00

49 lines
1.4 KiB
Diff

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