This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH v2 2/3] Cygwin: readlinkat: allow pathname to be empty
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin-patches at cygwin dot com" <cygwin-patches at cygwin dot com>
- Date: Sun, 29 Dec 2019 17:56:57 +0000
- Subject: [PATCH v2 2/3] Cygwin: readlinkat: allow pathname to be empty
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hrW+iTis3dhRWoNkd6xSIi6yonrQUAXFyfQRA8slrmw=; b=Kxoja8PX+jFsb4Xih2HhmtkI6GG80Nr4Si8lJWCjCkaZT2U3WEXB1+Y2Y9V2icq1w3aCFFMsHxSmreaOxKqxsuYycmXkthVcJidAibmYxT0NgevJbr0n1f99nzbov7Yt5MQCVTZah214FFJRcuRfGA1Uilz2ptLNuASLDrl+HlzP20I6sfz77j0mgLGCI6tAp4g3Oeyraqk94d4N62PVIb1V+GSrU/RkkYKtklMJJJXcogJjOl4dU9ucHGb1krDNwDLhTniTrWucBSu16qPAefISS9BTjpFnUyum1fguPndOMgZRmzqAP4m5xiTc1Qe6tEICnEX+MVyZI8mUTNCFTA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dGM1aZSXEkTQ6SjlHFSDPp48pkCp2EGJSsnK9m3J8MKVgq+g7hQLvthQuRZnK1a4bocvKoz8yuVN1B8InNoWO90FhfaDbSaPcr6NlWK34v+GlVzqkadq+PH9GjcuGdhqDSTJmM9cjC2Af1vaaxbWzUSyRQ6mNPvFWCji2cbAXR8GX8fdKuG8E2mNVdH1u8V9lAtSS7+xPQX26PLroEGHltMMEPo71ZCnNFI1+qT1r8tF19/HhUp/IxUMllJQ3KuegefPZtPs6Md506X4qxBP2/5UFV+ed1guWvqiwyyBP7bs0MZwjXoYKb9be0MEPkU+NgzBnVHkGxuL3+Sv43OZRQ==
- References: <20191229175637.1050-1-kbrown@cornell.edu>
Following Linux, allow the pathname argument to be an empty string,
provided the dirfd argument refers to a symlink opened with O_PATH and
O_NOFOLLOW. The readlinkat call then operates on that symlink.
---
winsup/cygwin/syscalls.cc | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 038a316db..2be8693c9 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -4979,8 +4979,23 @@ readlinkat (int dirfd, const char *__restrict pathname, char *__restrict buf,
__try
{
char *path = tp.c_get ();
- if (gen_full_path_at (path, dirfd, pathname))
- __leave;
+ int res = gen_full_path_at (path, dirfd, pathname);
+ if (res)
+ {
+ if (errno != ENOENT)
+ __leave;
+ /* pathname is an empty string. This is OK if dirfd refers
+ to a symlink that was opened with O_PATH and O_NOFOLLOW.
+ In this case, readlinkat operates on the symlink. */
+ cygheap_fdget cfd (dirfd);
+ if (cfd < 0)
+ __leave;
+ if (!(cfd->issymlink ()
+ && cfd->get_flags () & O_PATH
+ && cfd->get_flags () & O_NOFOLLOW))
+ __leave;
+ strcpy (path, cfd->get_name ());
+ }
return readlink (path, buf, bufsize);
}
__except (EFAULT) {}
--
2.21.0