Bug 60267 - Inconsistent symlink traversal results
Summary: Inconsistent symlink traversal results
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer (show other bugs)
Version: master
Hardware: PC Linux
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Alexis Christoforides
URL:
Depends on:
Blocks:
 
Reported: 2017-10-19 09:30 UTC by Piotr Zierhoffer
Modified: 2018-01-05 13:27 UTC (History)
6 users (show)

Tags: bugpool-archive
Is this bug a regression?: ---
Last known good build:


Attachments
The test program (523 bytes, text/x-csharp)
2017-10-19 09:30 UTC, Piotr Zierhoffer
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Piotr Zierhoffer 2017-10-19 09:30:24 UTC
Created attachment 25370 [details]
The test program

The bug appears when you try to verify the existence of a file in a directory, that is a symlink. The symlink may not point to a directory higher in the directory structure, it has to be on another branch. Moreover, you have to use ".." in a path, just after pointing to the directory in question

Steps to reproduce:

1) in the exe directory create the following directory structure:

-> test/
-->test2/
---> test_file
-> test3 -> test/test2 (test3 is a symlink to test/test2 dir. This structure is crucial)

2) run the attached code.

It checks the existence of "test3/../test3/" directory.

Directory.Exists fails, but Directory.GetFileSystemEntries works (prints the "test_file").

The same code DOES work on another directory structure:

-> test/
--> test_file
-> test2 -> test (test2 is a symlink to test dir)

Expected results:

Directory.Exists should understand symlinks, and handling of different directory structures should be consistent.
Comment 1 Ludovic Henry 2017-11-10 16:08:45 UTC
I can reproduce with Mono 5.8.0.40 (2017-10/ce494e3d152)

To reproduce, run following commands:
> mkdir test
> mkdir test/test2
> touch test/test2/test_file
> ln -s test/test2 test3
> csc repro.cs && mono repro.exe

Expected output:
> False
> True
> test3/../test3/test_file

Actual output:
> False
> False
> test3/../test3/test_file
Comment 2 Alexis Christoforides 2017-11-14 23:47:05 UTC
It seems that the lstat() syscall itself does not like that path. The solution may have to be part of mono_portability_find_file_internal()

Directory.Exists does work as expected under .NET Core 2.0.
Comment 3 Alexis Christoforides 2017-11-17 00:37:21 UTC
Candidate fix at https://github.com/mono/mono/pull/6039
Comment 4 Alexis Christoforides 2017-11-21 03:33:22 UTC
Fix merged to master