From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3370 invoked by alias); 12 Jun 2017 15:19:12 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41275 Received: (qmail 17205 invoked from network); 12 Jun 2017 15:19:11 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr0-f177.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.128.177):SA:0(0.0/5.0):. Processed in 1.257988 secs); 12 Jun 2017 15:19:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.128.177 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tER5gCkbPPVkcZU8/3wC4tkQODWQGOE6ub/NlcOwExU=; b=OLM2MXVp3bsaaRThBjwYzauCtPkv0CxiM+y1DUGIzZ3RQA5J/WEMticRNjqspGl+z1 4rfzO8uqk/8T8RBioWe2tNrJVaGwCEkblibCvqOApNSszrMzUnWf/G2upat51dErvcjW r82zK4PLglGykK52Pp4fAno9Ifti4cKF9DxoKh0dChDjJgYCLltmmLLKCV20JXgaglLt DOmySHRg+/IM7QK7KVuJemdDtTUT9SA8POre5rc/0NMpN93t2RF31hm4Bg6TCfcRwWQ8 f85Sl71dGOLrBmk01+OpV97b2ipiv06XRKD4CF4YPbqvmVMxttYLDVltwCF+SiIg1eZV WFoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=tER5gCkbPPVkcZU8/3wC4tkQODWQGOE6ub/NlcOwExU=; b=f3XVIjg4y+OaefBC/Qr2QSLucgu+Go5/zDk4IXYkMa1g5KZsPQusJRe+UFQ6w/datk BSVQKF3OTOnPMLLZQ5HDDh9mqOp/oew22drp2C/M700H7G6BFL5rpPlPZc/WkjBXfesT 6E2JZArv0hUIKkSiPTuA9mX4dofWWR4Oqp0kkzAKF8h4+klOnXES/Rl5M3M9ChxZzKCg XSEl9+AKHtWxzcKNu/LSqSkFG9Whl0oHA014SwQdAxGhXlYDnlDuBPEW58w8dCTRTuMS 8k7afYyDZL/w9pdb29IPEPaxKbseNQrFNtOl905Y02zcqVKnf31OXhAHvK3QxIMXJNYg jDBg== X-Gm-Message-State: AKS2vOwzmcO6D26d9sM2spxAhmFfuYmzpdsTpWZCoWg/opytnOJSR/Ng G4Nsel1nJwZJXg== X-Received: by 10.28.26.18 with SMTP id a18mr8018805wma.34.1497280744745; Mon, 12 Jun 2017 08:19:04 -0700 (PDT) Date: Mon, 12 Jun 2017 16:19:02 +0100 From: Stephane Chazelas To: Daniel Shahaf Cc: Zsh hackers list Subject: [PATCH3] Re: avoid closed stdin() in zle widgets Message-ID: <20170612151902.GA19315@chaz.gmail.com> Mail-Followup-To: Daniel Shahaf , Zsh hackers list References: <20170611182045.GA5318@chaz.gmail.com> <20170612060554.GA4709@chaz.gmail.com> <1497278089.1853864.1006670720.0A8DB74D@webmail.messagingengine.com> <20170612151042.GB3806@chaz.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170612151042.GB3806@chaz.gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) Even though I can't imagine previous relying on stdin being closed (and consider myself the previous behaviour a bug), please find a 3rd version of the patch below with the requested change: diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index b65e3be..bd0252f 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -745,22 +745,22 @@ User-defined widgets are defined using `tt(zle -N)', and implemented as shell functions. When the widget is executed, the corresponding shell function is executed, and can perform editing (or other) actions. It is recommended that user-defined widgets should not have names starting with `tt(.)'. sect(User-Defined Widgets) cindex(widgets, user-defined) User-defined widgets, being implemented as shell functions, can execute any normal shell command. They can also run other widgets -(whether built-in or user-defined) using the tt(zle) builtin command. -The standard input of the function is closed to prevent external commands -from unintentionally blocking ZLE by reading from the terminal, but -tt(read -k) or tt(read -q) can be used to read characters. Finally, -they can examine and edit the ZLE buffer being edited by -reading and setting the special parameters described below. +(whether built-in or user-defined) using the tt(zle) builtin command. The +standard input of the function is redirected from /dev/null to prevent +external commands from unintentionally blocking ZLE by reading from the +terminal, but tt(read -k) or tt(read -q) can be used to read characters. +Finally, they can examine and edit the ZLE buffer being edited by reading +and setting the special parameters described below. cindex(parameters, editor) cindex(parameters, zle) These special parameters are always available in widget functions, but are not in any way special outside ZLE. If they have some normal value outside ZLE, that value is temporarily inaccessible, but will return when the widget function exits. These special parameters in fact have local scope, like parameters created in a function using tt(local). diff --git a/NEWS b/NEWS index 568b160..e745750 100644 --- a/NEWS +++ b/NEWS @@ -9,16 +9,22 @@ Changes from 5.3.1 to 5.4 The 'exec' and 'command' precommand modifiers, and options to them, are now parsed after parameter expansion. Previously, both the modifier and any options to it were parsed between alias expansion and parameter expansion (see zshexpn(1)), so they could neither be quoted nor be the result of parameter expansion. Examples: 's=command; $s -V ls' and '\command -V ls' now work as expected. +Functions executed by ZLE widgets no longer have they standard input +closed, but is now redirected from /dev/null instead. That still guards +against user defined widgets inadvertently reading from the tty device, +and addresses the antisocial behaviour of running a command with its +stdin closed. + Changes from 5.2 to 5.3.1 ------------------------- There are only minor compatibility fixes between 5.3 and 5.3.1. It is possible to enable character width support for Unicode 9 by configuring with `--enable-unicode9'; this compiles in some additional diff --git a/README b/README index 432a35e..30023da 100644 --- a/README +++ b/README @@ -69,16 +69,22 @@ patch-format string, to prevent literal `%' signs in the interpolated value from being interpreted as prompt escape sequences. If you use ${vcs_info_msg_0_} in a context other than the shell prompt, you may need to undo the escaping with: print -v vcs_info_msg_0_ -Pr -- "${vcs_info_msg_0_}" This is also needed if $vcs_info_msg_0_ is used to set $psvar. +4) functions executed by ZLE widgets no longer have they standard input +closed, but is now redirected from /dev/null instead. That still guards +against user defined widgets inadvertently reading from the tty device, +and addresses the antisocial behaviour of running a command with its +stdin closed. + Incompatibilities between 5.0.8 and 5.3 ---------------------------------------- 1) In character classes delimited by "[" and "]" within patterns, whether used for filename generation (globbing) or other forms of pattern matching, it used not to be possible to quote "-" when used for a range, or "^" and "!" when used for negating a character set. The characters can now be quoted by any of the standard shell means, but note that diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 6c271b5..be2b062 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1480,16 +1480,23 @@ execzlefunc(Thingy func, char **args, int set_bindk) ret = execimmortal(func, args); } else { int osc = sfcontext, osi = movefd(0); int oxt = isset(XTRACE); LinkList largs = NULL; int inuse = w->flags & WIDGET_INUSE; w->flags |= WIDGET_INUSE; + if (osi > 0) { + /* + * Many commands don't like having a closed stdin, open on + * /dev/null instead + */ + open("/dev/null", O_RDWR | O_NOCTTY); /* ignore failure */ + } if (*args) { largs = newlinklist(); addlinknode(largs, dupstring(w->u.fnnam)); while (*args) addlinknode(largs, dupstring(*args++)); } startparamscope(); makezleparams(0);