From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23804 invoked by alias); 10 Feb 2015 11:13: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: 34494 Received: (qmail 28229 invoked from network); 10 Feb 2015 11:13:15 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=MkC//1QFKB7n3CrQyLwnMfGCXECsb6OY8xQkHf15G+M=; b=wOrwb4QiZq6GJo/aoJ7jmxPrIrik7YfjwY5qDJlv4YiaIjQ1s9hf4zA+gWXA3JmaSP TMlOjFjEyuaxcfeB9nGl88/5ioPTmGPQB3B6ZfMRGcNIlBMXwiO7uGdG6XBlFsS1k4Sa wErfuqwX1MRTxwbODcB6EGw8MOPtVMCslN/9a35UJLY1Lx1SEiWHjhwAThXsmHAeiGVG I5oAen6oUAOrDoDPNUTom8f00KRfhJpApcllfICCOBJO8ff+6t9SsMiJrZhjz0W0OMNc Xh918hVhfC5SW8Y651SFHe/2tcH1pisGkgfQBnzO0MVJQcadzmq6VbMAeeoeUQu/AmQK qtUg== MIME-Version: 1.0 X-Received: by 10.50.79.161 with SMTP id k1mr22463158igx.14.1423566792221; Tue, 10 Feb 2015 03:13:12 -0800 (PST) In-Reply-To: <20150210093729.476bab46@pwslap01u.europe.root.pri> References: <1423552346-18827-1-git-send-email-mikachu@gmail.com> <20150210093729.476bab46@pwslap01u.europe.root.pri> Date: Tue, 10 Feb 2015 12:13:12 +0100 Message-ID: Subject: Re: PATCH: Fix use-after-free for print -zf and print -sf From: Mikael Magnusson To: Peter Stephenson Cc: zsh workers Content-Type: text/plain; charset=UTF-8 On Tue, Feb 10, 2015 at 10:37 AM, Peter Stephenson wrote: > On Tue, 10 Feb 2015 08:16:56 +0100 > Mikael Magnusson wrote: >> On Tue, Feb 10, 2015 at 8:12 AM, Mikael Magnusson wrote: >> > /* Testing EBADF special-cases >&- redirections */ >> > - if ((fout != stdout) ? (fclose(fout) != 0) : >> > + if (fout && (fout != stdout) ? (fclose(fout) != 0) : >> >> Do I need an extra set of parens here? C precedence rules are fun. >> > > https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence > > "&&" is higher precedence than ?: so this looks OK. > > I suppose it's at the point where a lot of people would decide it needed > expanding into something clearer, but it's a reasonable extension of > what was there before. Can't see a problem with it. Oops, actually I think I do need it, since I want fout being NULL to short circuit the whole if statement to false, and currently it's interpreted as if ((fout && (fout != stdout)) ? .. : ..), resulting in a call to fflush(NULL) which flushes all open output buffers. I should probably have quoted both lines of the if. :) -- Mikael Magnusson