Web lists-archives.com

# RE: winsup\cygwin\path.cc issues

• Date: Wed, 30 May 2018 01:04:10 +0000
• From: Ken Harris <Ken.Harris@xxxxxxxxxxxxx>
• Subject: RE: winsup\cygwin\path.cc issues

```Thank you so much, Corinna: So far - it looks great. I'll roll your patch into our MSYS2 build which will exercise it about as widely as we possibly can. If I see anything amiss, I'll track it down, and if I can repro in Cygwin alone, I'll report back.
Again, Thanks!
-Ken

-----Original Message-----
From: Corinna Vinschen [mailto:corinna-cygwin@xxxxxxxxxx]
Sent: Tuesday, May 29, 2018 12:32 PM
To: cygwin@xxxxxxxxxx
Cc: Ken Harris <Ken.Harris@xxxxxxxxxxxxx>
Subject: Re: winsup\cygwin\path.cc issues

Hi Ken,

On May  4 01:23, Ken Harris wrote:
> Hi Marco: Sorry for not replying to the original exchange we had. I
> wasn't subscribed to the list but now I am so it won't happen again
> (so I'm quoting our exchange below).
>
>                 I installed and built cygwin1.dll with an added assert
>                 in path.cc to identify when the buffer underrun
>                 condition I originally described occurs:
>
> \$ diff -b
> ./cygwin-2.10.0-1.src/newlib-cygwin/winsup/cygwin/path.cc.ORIG
> ./cygwin-2.10.0-1.src/newlib-cygwin/winsup/cygwin/path.cc 2803c2803 <
> ; ---
> >                   assert(p >= path);
>
>                 Thus, a simple:
>
>                 cat '\A../../../B'
>
>                 will result in the assert firing:
>
> kharris@ah-kharris /usr/src \$ cat '\A../../../B' assertion "p >= path"
> failed: file "../../.././winsup/cygwin/path.cc", line 2803, function:
> int symlink_info::check(char*, const suffix_info*, fs_info&,
> path_conv_handle&) Aborted (core dumped)
>
> Attached is a patch (in addition to the added assert) with what I
> *think* might really fix the problem. This was where the expected
> backslash got squashed which allowed symlink_info::check() to go
> "negative" with its 'p' pointer and look for a backslash in someone
> else's memory.

Thanks for your preliminary work, but as far as I can see this isn't the entire solution.  The same problem occurs if your CWD is the root of a drive, e.g., C:\, and you call cat A../../../B.  Even simpler, try `cat 'C:\A../../../B''

The reason is that the code in normalize_win32_path never actually ignores drive prefixes.  There's an implicit (and oh so wrong) assumption that any path starts with a slash or backslash one way or the other.
It's pretty weird that it took so long to find this blatant problem.

I applied a patch which hopefully fixes this problem in all code paths:
https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=35998fc2fa6c

I also left your assertion in the code for now as an additional patch https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=7d00a5e320db
just to be sure, but I will take this out again before a release.

I uploaded new developer snapshots to https://cygwin.com/snapshots/
containing the above patches.  Please give them a try.

Thanks,
Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat
```