🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.bash.bug
Article #177

Re: && causing bash to dump core

#177
From: Chet Ramey
Date: Thu, 29 Jun 1989 22:13
54 lines
2733 bytes
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
Technical Details
Message-ID: <385@cwjcc.CWRU.Edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!cwjcc!kiwi!chet
References: <89Jun29.100903edt.10374@neat.ai.toronto.edu> <89Jun29.104738edt.10370@neat.ai.toronto.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!cwjcc!kiwi!chet
From: chet@kiwi.CWRU.EDU (Chet Ramey)
Newsgroups: gnu.bash.bug
Subject: Re: && causing bash to dump core
Summary: FIX
Message-ID: <385@cwjcc.CWRU.Edu>
Date: 29 Jun 89 22:13:59 GMT
References: <89Jun29.100903edt.10374@neat.ai.toronto.edu> <89Jun29.104738edt.10370@neat.ai.toronto.edu>
Sender: news@cwjcc.CWRU.Edu
Reply-To: chet@kiwi.CWRU.EDU (Chet Ramey)
Organization: CWRU Andrew R. Jennings Computing Center
Lines: 54