zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: [PATCH3] Re: avoid closed stdin() in zle widgets
Date: Thu, 15 Jun 2017 09:42:44 +0100	[thread overview]
Message-ID: <20170615084244.GB2416@chaz.gmail.com> (raw)
In-Reply-To: <170614154425.ZM20199@torch.brasslantern.com>

2017-06-14 15:44:25 -0700, Bart Schaefer:
> On Jun 12,  8:02pm, Stephane Chazelas wrote:
> }
> } My point is that a command should be able to reasonably make some
> } assumptions, like:
> } 
> } - stdin should be open for at least reading
> } - stdout, stderr should be open for at least writing
> 
> Although I understand the security implication of accidentally opening
> some other file onto fd 0/1/2, I can't agree with the above statements.
> Taken to the logical conclusion, the >&- <&- or 2>&- operators would
> be required always to fail with an error.
> 
> It should not be the shell's job to plug this hole.  I will agree that
> a valid argument is that the shell should not implicitly *open* this
> hole, which one could also argue is what the completion system had
> been doing in spite of the behavior being documented.  However, with
> these two likely exceptions --
> 
> } - argv[0] should be set (argc > 0)
> } - no dups in the environment
> 
> -- there is nothing else on your list where I would agree that the
> shell should ignore the user's directives in the name of protecting
> an external command from itself.

I think you misinterpreted what I said, I did not imply that the
shell should take upon itself to prevent users from creating
those pathological conditions, but that it should not take upon
itself to creating those pathological conditions itself.

That's the "Be conservative in what you do" in the "Be
conservative in what you do, be liberal in what you accept from
others" (and yes, it's a case where "dircolors" did not fully
apply the "be liberal in what you accept").

In other words, I would certainly not want zsh to refuse to <&-
just like I would not want close(0) in C to fail.

I would even welcome new options to the "env" utility to execute
a command without arguments or with arbitrary argv[0], or with
duplicate env vars or with env strings without = characters so
one can test applications in those pathological conditions (and
possibly raise awareness on the security implications), but
if we put aside those testing cases, an application like zsh
should not intentionaly (by itself) cause those pathological
conditions.

The case of zle widgets running commands with stdin close was
not a case where the user requested stdin to be closed.

> } $ (limit stacksize 100k; zsh)
> } zsh: segmentation fault
> } zsh: segmentation fault
> } 
> } (twice!?). Is that a bug?
> 
> I believe what's happening is that both the zsh inside the subshell
> and the parent handling the subshell exit are reporting the error,
> so one failure / two messages.
> 
> However, I can't test directly because I can start zsh -f with a hard
> limit stack size of *zero*, so I'm quite curious as to why you get a
> crash on 100k.

I suspect your system won't bring the stack size below some
threshold (or just ignores that  limit). With a null stack size,
you woudn't even be able to call execve()

My several segvs were probably down to some child processes
spawned by my ~/.zshrc dying there upon stack overflow.

The point was just an illustration that you can't always deal
with all pathological conditions, you have to put a limit on
the amount of effort you're willing to put into covering for all
possible pathological cases, and IMO a closed stdin is one such
pathological case (even if not as much as a very small stack
size, or random memory bit flips), and one you can blame on the
calling application.

-- 
Stephane


  reply	other threads:[~2017-06-15  8:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-11 18:20 [PATCH] " Stephane Chazelas
2017-06-12  4:15 ` Eric Cook
2017-06-12  6:05   ` [PATCH2] " Stephane Chazelas
2017-06-12 14:34     ` Daniel Shahaf
2017-06-12 15:10       ` Stephane Chazelas
2017-06-12 15:19         ` [PATCH3] " Stephane Chazelas
2017-06-12 15:34           ` Daniel Shahaf
2017-06-12 16:09             ` Bart Schaefer
2017-06-12 19:02               ` Stephane Chazelas
2017-06-14 22:44                 ` Bart Schaefer
2017-06-15  8:42                   ` Stephane Chazelas [this message]
2017-06-17  3:03                     ` Bart Schaefer

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=20170615084244.GB2416@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).