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/

Reply via email to