From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27066 invoked by alias); 13 Aug 2017 21:45:18 -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: 41541 Received: (qmail 4142 invoked by uid 1010); 13 Aug 2017 21:45:18 -0000 X-Qmail-Scanner-Diagnostics: from mail-qk0-f173.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.220.173):SA:0(0.5/5.0):. Processed in 1.997359 secs); 13 Aug 2017 21:45:18 -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.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_SPAM,SPF_PASS, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=LphoVh/UWZaVQJF7uKbmr01lxB+ydnnr3/9Fa0GM5+I=; b=Dsn/6je7rNj8smdVflV/aoVH3aWpJR3elimHwPyd3GuDVG0Lsqb5WHF8l0c0qSF9Bf k6yjuvaNVy2BgHnksigz8wWggeVTXGUKqiRpeHjTGf00MCoFfq6NVUg6AlJab/TA+Ns4 C2i8+6Z7pltGrF9xOsmAr7lEJYr1ie/gjuOGne1fWfUyrFrY5sV9MbueDOp4UdRe63j3 XvSmjUXHe5Y7xR7JD1zOTXtT+SRsr90kaYQLzYNFUdmOHxsWrIYJRKiuCI92CGWeHXWJ PqW3KQkdABebgoyyRZyo9GxQqGKmMEkVH3G3U/jTqb6LEQmhHDoc5Gr0b+FSNbbdw1Pt t92Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=LphoVh/UWZaVQJF7uKbmr01lxB+ydnnr3/9Fa0GM5+I=; b=kOyNd8RTOZZ5m9SF7Fy9AAobANfArOoM9N5lFfJf0r3kPM3snKVikKGmaqd4wfBHI8 g2QrhS5MCQiltzXSNspsRbHjTxCJK20TKBeCueCxq/HXJpqUneAT9u2mHnMnzyDQ/RRd p75LmXbn63I4mS1i7PTKEoSSyiGP3J2scZN7FoyL/iV0jIt0OJ4G2aZOm2zTg39L17n4 s03rktTjaqjDf1yhJjjXdryVigZ6hzPL4rFnIT+z9najmGvf/au25O++uKhJKOlxSJJv +gqYavr5w3p/vhApQ0XHx+T4OQzGxIsTDyi29NxbfaN4ouV4T6Qzid7plfSWvHG3kfWl F/Jg== X-Gm-Message-State: AHYfb5jZxW4HizmRfTwur0WqgwC2WJCOtns33a4+DdI9sFfhDeukou4o Mv3ZmdJrL4H/rbuYxsMQooGkLBe0MbHi X-Received: by 10.55.156.9 with SMTP id f9mr29603048qke.141.1502660713033; Sun, 13 Aug 2017 14:45:13 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20170813194939.7a96bc4b@ntlworld.com> References: <20170813161207.GA6530@chaz.gmail.com> <20170813194939.7a96bc4b@ntlworld.com> From: Bart Schaefer Date: Sun, 13 Aug 2017 14:45:12 -0700 Message-ID: Subject: Re: fd used for saving redirected fds leaked to child processes To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" On Sun, Aug 13, 2017 at 11:49 AM, Peter Stephenson wrote: > > +/* FDs saved for possible restoring, not needed in a subshell > + * where we will never need to restore them. Hence if we enter > + * a subshell these will simply be closed unconditionally. > + * > + * A value >= 10 indicates a valid saved fd. > + */ No objection to defensive programming, but would it not be a bug for an fd < 10 to ever be assigned to a slot in saved_fds[] in the first place? It feels as though there's probably a reason that (int *save) is passed around as a parameter to addfd() et al. rather than being a global to begin with. Are you sure there aren't circumstances where the same fd might get saved more than once at different levels of the recursive execsomething() hierarchy, causing saved_fds[] to contain incomplete information? I'm envisioning something like { { cmd1 ; cmd2 } > file2; cmd3 } > file1 &