Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Fix use-after-free for print -zf and print -sf



On Tue, Feb 10, 2015 at 12:18 PM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Tue, 10 Feb 2015 12:13:12 +0100
> Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>> 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. :)
>
> Yes, I missed that... that's kind of why I talked about rewriting it...
>
> pws

-    /* Testing EBADF special-cases >&- redirections */
-    if (fout && ((fout != stdout) ? (fclose(fout) != 0) :
-       (fflush(fout) != 0 && errno != EBADF))) {
-       zwarnnam(name, "write error: %e", errno);
-       ret = 1;
-    }
+#ifdef HAVE_OPEN_MEMSTREAM
+    if (fout)
+#endif
+       /* Testing EBADF special-cases >&- redirections */
+       if ((fout != stdout) ? (fclose(fout) != 0) :
+           (fflush(fout) != 0 && errno != EBADF)) {
+           zwarnnam(name, "write error: %e", errno);
+           ret = 1;
+       }
     return ret;
 }

This would make it very clear that fout can only be NULL in one very
particular case, and also leaves the main EBADF thing the same as the
other places in the function... (sorry for bikeshedding so much over
this). Which of these do you prefer?

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author