public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH] Cygwin: fix return value of symlink_info::check
Date: Wed, 10 Aug 2022 09:49:10 +0200	[thread overview]
Message-ID: <YvNi9pnVkw6B22PG@calimero.vinschen.de> (raw)
In-Reply-To: <5bb753d7-a56a-d551-c675-26e4f822068e@cornell.edu>

On Aug  9 16:52, Ken Brown wrote:
> v2 attached with a more accurate commit message.

LGTM, please push.


Thanks,
Corinna

> 
> Ken
> 
> On 8/9/2022 3:52 PM, Ken Brown wrote:
> > Patch attached.  Please check my changes to the commentary preceding
> > symlink_info::check to make sure I got it right.
> > 
> > I've written the patch against the master branch, but I think it should
> > be applied to cygwin-3_3-branch also.
> > 
> > Ken

> From d1aee2f7e022497d57d55ffcd69ddaa7d7b123b2 Mon Sep 17 00:00:00 2001
> From: Ken Brown <kbrown@cornell.edu>
> Date: Tue, 9 Aug 2022 15:14:07 -0400
> Subject: [PATCH v2] Cygwin: fix return value of symlink_info::check
> 
> Currently it is possible for symlink_info::check to return -1 in case
> we're searching for foo and find foo.lnk that is not a Cygwin symlink.
> This contradicts the new meaning attached to a negative return value
> in commit 19d59ce75d.  Fix this by setting "res" to 0 at the beginning
> of the main loop and not seting it to -1 later.
> 
> Also fix the commentary preceding the function definition to reflect
> the current behavior.
> 
> Addresses: https://cygwin.com/pipermail/cygwin/2022-August/252030.html
> ---
>  winsup/cygwin/path.cc       | 22 +++++++++-------------
>  winsup/cygwin/release/3.3.6 |  4 ++++
>  2 files changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
> index 3e436dc65..227b99d0f 100644
> --- a/winsup/cygwin/path.cc
> +++ b/winsup/cygwin/path.cc
> @@ -3027,19 +3027,16 @@ symlink_info::parse_device (const char *contents)
>  /* Check if PATH is a symlink.  PATH must be a valid Win32 path name.
>  
>     If PATH is a symlink, put the value of the symlink--the file to
> -   which it points--into BUF.  The value stored in BUF is not
> -   necessarily null terminated.  BUFLEN is the length of BUF; only up
> -   to BUFLEN characters will be stored in BUF.  BUF may be NULL, in
> -   which case nothing will be stored.
> +   which it points--into CONTENTS.
>  
> -   Set *SYML if PATH is a symlink.
> +   Set PATH_SYMLINK if PATH is a symlink.
>  
> -   Set *EXEC if PATH appears to be executable.  This is an efficiency
> -   hack because we sometimes have to open the file anyhow.  *EXEC will
> -   not be set for every executable file.
> -
> -   Return -1 on error, 0 if PATH is not a symlink, or the length
> -   stored into BUF if PATH is a symlink.  */
> +   If PATH is a symlink, return the length stored into CONTENTS.  If
> +   the inner components of PATH contain native symlinks or junctions,
> +   or if the drive is a virtual drive, compare PATH with the result
> +   returned by GetFinalPathNameByHandleA.  If they differ, store the
> +   final path in CONTENTS and return the negative of its length.  In
> +   all other cases, return 0.  */
>  
>  int
>  symlink_info::check (char *path, const suffix_info *suffixes, fs_info &fs,
> @@ -3094,6 +3091,7 @@ restart:
>  
>    while (suffix.next ())
>      {
> +      res = 0;
>        error = 0;
>        get_nt_native_path (suffix.path, upath, mount_flags & MOUNT_DOS);
>        if (h)
> @@ -3345,8 +3343,6 @@ restart:
>  	  continue;
>  	}
>  
> -      res = -1;
> -
>        /* Reparse points are potentially symlinks.  This check must be
>  	 performed before checking the SYSTEM attribute for sysfile
>  	 symlinks, since reparse points can have this flag set, too. */
> diff --git a/winsup/cygwin/release/3.3.6 b/winsup/cygwin/release/3.3.6
> index 078e6e520..364e0cb0d 100644
> --- a/winsup/cygwin/release/3.3.6
> +++ b/winsup/cygwin/release/3.3.6
> @@ -35,3 +35,7 @@ Bug Fixes
>  - Fix a problem that prevented some symbolic links to /cygdrive/C,
>    /cygdrive/./c, /cygdrive//c, etc. from working.
>    Addresses: https://cygwin.com/pipermail/cygwin/2022-July/251994.html
> +
> +- Fix a path handling bug that could cause a non-existing file to be
> +  treated as the current directory.
> +  Addresses: https://cygwin.com/pipermail/cygwin/2022-August/252030.html
> -- 
> 2.37.1
> 


      reply	other threads:[~2022-08-10  7:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 19:52 Ken Brown
2022-08-09 20:52 ` Ken Brown
2022-08-10  7:49   ` Corinna Vinschen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YvNi9pnVkw6B22PG@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).