summaryrefslogtreecommitdiff
path: root/debian/patches/fix-utimensat-test.patch
blob: 2f994aafd9252ae71b9fa058b7c8048123ba35a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From 0c3b0631695be33f711eda233bfee3dab77d405c Mon Sep 17 00:00:00 2001
From: Darren Tucker <dtucker@dtucker.net>
Date: Fri, 7 Jun 2019 23:47:37 +1000
Subject: Update utimensat test.

POSIX specifies that when given a symlink, AT_SYMLINK_NOFOLLOW should
update the symlink and not the destination.  The compat code doesn't
have a way to do this, so where possible it fails instead of following a
symlink when explicitly asked not to. Instead of checking for an explicit
failure, check that it does not update the destination, which both the
real and compat implementations should honour.

Inspired by github pull req #125 from chutzpah at gentoo.org.

Origin: upstream, https://anongit.mindrot.org/openssh.git/commit/?id=182898192d4b720e4faeafd5b39c2cfb3b92aa21
Last-Update: 2019-06-09

Patch-Name: fix-utimensat-test.patch
---
 openbsd-compat/regress/utimensattest.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/openbsd-compat/regress/utimensattest.c b/openbsd-compat/regress/utimensattest.c
index a7bc7634b..b29cef2f1 100644
--- a/openbsd-compat/regress/utimensattest.c
+++ b/openbsd-compat/regress/utimensattest.c
@@ -83,14 +83,28 @@ main(void)
 		fail("mtim.tv_nsec", 45678000, sb.st_mtim.tv_nsec);
 #endif
 
+	/*
+	 * POSIX specifies that when given a symlink, AT_SYMLINK_NOFOLLOW
+	 * should update the symlink and not the destination.  The compat
+	 * code doesn't have a way to do this, so where possible it fails
+	 * with ENOSYS instead of following a symlink when explicitly asked
+	 * not to.  Here we just test that it does not update the destination.
+	 */
 	if (rename(TMPFILE, TMPFILE2) == -1)
 		fail("rename", 0, 0);
 	if (symlink(TMPFILE2, TMPFILE) == -1)
 		fail("symlink", 0, 0);
+	ts[0].tv_sec = 11223344;
+	ts[1].tv_sec = 55667788;
+	(void)utimensat(AT_FDCWD, TMPFILE, ts, AT_SYMLINK_NOFOLLOW);
+	if (stat(TMPFILE2, &sb) == -1)
+		fail("stat", 0, 0 );
+	if (sb.st_atime == 11223344)
+		fail("utimensat symlink st_atime", 0, 0 );
+	if (sb.st_mtime == 55667788)
+		fail("utimensat symlink st_mtime", 0, 0 );
 
-	if (utimensat(AT_FDCWD, TMPFILE, ts, AT_SYMLINK_NOFOLLOW) != -1)
-		fail("utimensat followed symlink", 0, 0);
-
+	/* Clean up */
 	if (!(unlink(TMPFILE) == 0 && unlink(TMPFILE2) == 0))
 		fail("unlink", 0, 0);
 	exit(0);