chet@kiwi.CWRU.EDU (Chet Ramey) (06/30/89)
In article <89Jun29.104738edt.10370@neat.ai.toronto.edu> lamy@ai.utoronto.ca (Jean-Francois Lamy) writes: >lamy@ai.utoronto.ca (Jean-Francois Lamy) writes: >>a) a .bashrc that contains >> if [ "$PS1" != "" && $SHLVL -gt 1 ] >> then >> echo bah >> fi >> will cause bash to dump core; said code appears to produce an error message >> (cryptic as it may be) as it should when the shell is run interactively > >This is on Sun 3 and Sun 4, SunOS 4.0.1. I can dig up the debugger should the >bug prove hard to reproduce elsewhere. It is easy to reproduce (and fairly easy to fix). First of all, bash is parsing this correctly, and passing an argv to the test command that looks like {"[","","!=","",0} because && means "run the command after && if the command before && succeeds". The test command, in test_command, checks for the existing of matching brackets, and calls test_syntax_error if margv[margc] != "]" when margv[0] == "[". Unfortunately, the first thing test_syntax_error does is fprintf(stderr,"%s: ", argv[0]). No-no, bang, crash. `argv' is still garbage; `margv' is what was passed to test_command. One possible fix is to add the assignment "argv = margv" right before the call to test_syntax_error(), to wit (this diff is against vanilla bash 1.01 test.c): *** test.c.1.01 Fri Jun 23 00:43:13 1989 --- test.c Thu Jun 29 18:04:10 1989 *************** *** 687,690 test_exit (SHELL_BOOLEAN (FALSE)); if (']' != margv[margc][0] || '\000' != margv[margc][1]) { test_syntax_error ("missing `]'\n"); } --- 687,691 ----- test_exit (SHELL_BOOLEAN (FALSE)); if (']' != margv[margc][0] || '\000' != margv[margc][1]) { + argv = margv; /* for test_syntax_error */ test_syntax_error ("missing `]'\n"); } There are other problems with test, I am putting together some fixes that will probably go out tomorrow. Chet Chet Ramey "We are preparing to think about contemplating Network Services Group, CWRU preliminary work on plans to develop a chet@cwjcc.INS.CWRU.Edu schedule for producing the 10th Edition of the Unix Programmers Manual." -- Andrew Hume