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 1/2] Cygwin: format_process_fd: add directory check
Date: Tue, 8 Sep 2020 21:13:11 +0200	[thread overview]
Message-ID: <20200908191311.GR4127@calimero.vinschen.de> (raw)
In-Reply-To: <20200908165048.47566-2-kbrown@cornell.edu>

Hi Ken,

On Sep  8 12:50, Ken Brown via Cygwin-patches wrote:
> The incoming path is allowed to have the form "$PID/fd/[0-9]*/.*"
> provided the descriptor symlink points to a directory.  Check that
> this is indeed the case.
> ---
>  winsup/cygwin/fhandler_process.cc | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc
> index a6c358217..888604e3d 100644
> --- a/winsup/cygwin/fhandler_process.cc
> +++ b/winsup/cygwin/fhandler_process.cc
> @@ -398,6 +398,21 @@ format_process_fd (void *data, char *&destbuf)
>  	*((process_fd_t *) data)->fd_type = virt_fdsymlink;
>        else /* trailing path */
>  	{
> +	  /* Does the descriptor link point to a directory? */
> +	  bool dir;
> +	  if (*destbuf != '/')	/* e.g., "pipe:[" or "socket:[" */
> +	    dir = false;
> +	  else
> +	    {
> +	      path_conv pc (destbuf);
> +	      dir = pc.isdir ();
> +	    }
> +	  if (!dir)
> +	    {
> +	      set_errno (ENOTDIR);
> +	      cfree (destbuf);
> +	      return -1;
> +	    }
>  	  char *newbuf = (char *) cmalloc_abort (HEAP_STR, strlen (destbuf)
>  							   + strlen (e) + 1);
>  	  stpcpy (stpcpy (newbuf, destbuf), e);
> -- 
> 2.28.0

Huh, I'd never realized this check is missing.  I was just puzzeling
over your patch, searching for the directory check, but yeah, there is
none.  Please push.


Thanks,
Corinna

  reply	other threads:[~2020-09-08 19:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 16:50 [PATCH 0/2] Fix problems with /proc/<pid>/fd checking Ken Brown
2020-09-08 16:50 ` [PATCH 1/2] Cygwin: format_process_fd: add directory check Ken Brown
2020-09-08 19:13   ` Corinna Vinschen [this message]
2020-09-08 16:50 ` [PATCH 2/2] Cygwin: path_conv::check: handle error from fhandler_process::exists Ken Brown
2020-09-08 18:57   ` Ken Brown

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=20200908191311.GR4127@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).