X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: Re: bug with built-in commands in bash when redirecting output Date: Wed, 24 Jan 2007 03:38:13 +0000 (UTC) Lines: 33 Message-ID: References: <45B638BE DOT 80003 AT acm DOT org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Eric Blake byu.net> writes: > > So, I retract that it is a cygwin bug, and instead claim it is an upstream bash > bug. It is solved by doing freopen(NULL,"w",stdout) after replacing the fd, > since that is the mechanism for telling stdio that it should please choose the > correct text or binary mode based on the new underlying fd. Also vulnerable is executing a pipeline with a shell builtin when the shell's stdout is in text mode (I suppose a parallel bug exists with the read builtin on the receiving end of a pipe, but can't come up with a way to test it, since read is not designed to be executed in a pipeline). $ bash -c 'echo hi | od -tx1z' | cat -A 0000000 68 69 0a >hi.<$ 0000003$ $ bash -c 'echo hi | od -tx1z' > ~/text/x $ cat -A ~/text/x 0000000 68 69 0d 0a >hi..<$ 0000004$ $ bash -c '/bin/echo hi | od -tx1z' > ~/text/x $ cat -A ~/text/x 0000000 68 69 0a >hi.<$ 0000003$ The fix to | is separate to the fix for ``, but both instances of builtins using stdout to pipes will be fixed in the next bash package. -- Eric Blake -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/