delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/01/23/22:38:47

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Blake <ebb9 AT byu DOT net>
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: <loom.20070124T041948-959@post.gmane.org>
References: <45B638BE DOT 80003 AT acm DOT org> <loom DOT 20070123T193447-734 AT post DOT gmane DOT org> <loom DOT 20070123T221146-200 AT post DOT gmane DOT org>
Mime-Version: 1.0
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: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 <ebb9 <at> 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019