This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bash dumps stack after writing to /etc


A bug is found that might be located in cygwin or bash.

Bash dumps stack on exit if all of the following requirements are true:
- Bash was started from a windows batch script
- Bash was started in non-interactive mode to execute a script
- The script includes an attempt to write (pipe) data to a file in /etc
- The write attempt is enclosed by an if clause.

To reproduce the bug, start a windows batch script that starts bash in
non-interactive mode running a bash script that within an if clause
attempts to write to a file in the /etc directory. This will result in a bash
stack dump, at least on Windows 7 Professional SP1.

As an example, place example*.bat and script*.bash (code listed below)
in the cygwin root folder. Then start the batch files via the Windows GUI.

example1-breaks.bat reproduces the bug.
example1i-works.bat shows that bash works like expected in interactive mode.
example2-works.bat shows that bash works like expected when writing to
a file outside of /etc.
example3-maybe.bat shows that the if clause might change the behaviour.

File listing follows. Make sure to save the .bat files with windows
linebreaks, and the .bash files with unix linebreaks.

example1-breaks.bat:
@echo off
%~d0
cd %~dp0
bin\bash.exe script1.bash
pause

example1i-works.bat:
@echo off
%~d0
cd %~dp0
bin\bash.exe -i script1.bash
pause

example2-works.bat:
@echo off
%~d0
cd %~dp0
bin\bash.exe script2.bash
pause

example3-maybe.bat:
@echo off
%~d0
cd %~dp0
bin\bash.exe script3.bash
pause

script1.bash:
#!/bin/bash
PATH="/bin:$PATH"
if true; then
echo hello > /etc/hello
fi

script2.bash:
#!/bin/bash
PATH="/bin:$PATH"
if true; then
echo hello > /hello
fi

script3.bash:
#!/bin/bash
PATH="/bin:$PATH"
echo hello > /etc/hello
fi




System information:
Machine: i686
OS: cygwin on Windows 7 Professional SP1
Compiler: gcc-4
Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' -DCONF_VENDOR='pc'
-DLOCALEDIR='/usr/$
uname output: CYGWIN_NT-6.1 Machine-name 1.7.16(0.262/5/3) 2012-07-20 22:55
i686 Cygwin
Machine Type: i686-pc-cygwin
See also attached cygcheck.out. It was created by cygcheck running
independently from any cygwin installation. "WITHHELD" denotes a
manual alteration.

Attachment: cygcheck.out
Description: Binary data

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]