Cygwin: format_process_fd: add directory check

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.
This commit is contained in:
Ken Brown 2020-09-08 11:45:09 -04:00
parent eaed594d73
commit 58cc67d653
1 changed files with 15 additions and 0 deletions

View File

@ -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);