mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-19 07:22:14 +08:00
Cygwin: fix Win32 path ".." backtracking
Commit 35998fc2fa6cbb7d761f6d88346246bd3627552b fixed the buffer underun in win32 path normalization, but introduced a new bug: A wrong assumption led to the inability to backtrack the path outside of the current working directory in case of relative paths. This patch fixes this problem, together with a minor problem if the CWD is on a network share: The result erroneously started with tripple backslash if the src path starts with a single backslash. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
a9cfb33b6c
commit
3a880bf5e0
@ -1394,14 +1394,27 @@ normalize_win32_path (const char *src, char *dst, char *&tail)
|
||||
}
|
||||
else if (*src != '/')
|
||||
{
|
||||
/* Make sure dst points to the rightmost backslash which must not
|
||||
be backtracked over during ".." evaluation. This is either
|
||||
the backslash after the network path prefix (i.e. "\\") or
|
||||
the backslash after a drive letter (i.e. C:\"). */
|
||||
if (beg_src_slash)
|
||||
dst = (tail += cygheap->cwd.get_drive (dst));
|
||||
{
|
||||
tail += cygheap->cwd.get_drive (dst);
|
||||
/* network path, drive == '\\\\'? Decrement tail to avoid
|
||||
triple backslash in output. */
|
||||
if (dst[0] == '\\')
|
||||
--tail;
|
||||
dst = tail;
|
||||
}
|
||||
else if (cygheap->cwd.get (dst, 0))
|
||||
{
|
||||
tail = strchr (tail, '\0');
|
||||
if (tail[-1] != '\\')
|
||||
*tail++ = '\\';
|
||||
dst = tail - 1;
|
||||
++dst;
|
||||
if (dst[1] == '\\')
|
||||
++dst;
|
||||
}
|
||||
else
|
||||
return get_errno ();
|
||||
@ -1428,9 +1441,7 @@ normalize_win32_path (const char *src, char *dst, char *&tail)
|
||||
}
|
||||
|
||||
/* Backup if "..". */
|
||||
else if (src[0] == '.' && src[1] == '.'
|
||||
/* dst must be greater than dst_start */
|
||||
&& tail[-1] == '\\')
|
||||
else if (src[0] == '.' && src[1] == '.' && tail[-1] == '\\')
|
||||
{
|
||||
if (!isdirsep (src[2]) && src[2] != '\0')
|
||||
*tail++ = *src++;
|
||||
|
13
winsup/cygwin/release/2.11.1
Normal file
13
winsup/cygwin/release/2.11.1
Normal file
@ -0,0 +1,13 @@
|
||||
What's new:
|
||||
-----------
|
||||
|
||||
|
||||
What changed:
|
||||
-------------
|
||||
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- Fix ".." handling in Win32 path normalization, introduced in 2.11.0.
|
||||
Addresses: https://cygwin.com/ml/cygwin/2018-09/msg00000.html
|
Loading…
x
Reference in New Issue
Block a user