Segfault in bash 3.0

2005-11-14 Thread Ben Cotterell
bash version 3.0 crashes with a segmentation fault when running this
script:

#!/bin/bash
# Running this script crashes bash version 3.0 (and 2.05b.0(1))

function foo
{ 
local w
local c
c=([EMAIL PROTECTED] and stuff)
echo [EMAIL PROTECTED]
}

w=/tmp
foo

I tried to be helpful and investigate the bug. Here is my fix:

--- variables.c 2005-11-11 23:40:53.288909032 +
+++ ../org/bash-3.0/variables.c 2004-07-04 18:57:26.0 +0100
@@ -1643,12 +1643,6 @@
 things like `x=4 local x'. */
   if (was_tmpvar)
 var_setvalue (new_var, savestring (tmp_value));
-  else
-{
-  char *value = (char *)xmalloc (1); /* like do_assignment_internal 
*/
-  value[0] = '\0';
-  var_setvalue (new_var, value);
-}
 
   new_var->attributes = exported_p (old_var) ? att_exported : 0;
 }

Discussion of fix follows:

The crash is caused directly by a NULL string turning up in a place
where the worst that was expected was an empty string. It's when we're
expanding the [EMAIL PROTECTED] expression that we hit the problem.

So there seem to be two ways to fix it:

1. Why is the string NULL, should it be empty? Make sure it's never
NULL.

This seems most likely to be the right fix. There's code in a few places
that does this kind of thing (do_assignment_internal and assign_in_env).

The problem only seems to be caused when a global variable is shadowed
by an uninitialized local, and then used in a [EMAIL PROTECTED] expression. 

The call to make_new_variable, in make_local_variable, variables.c: 1641
is where it gets set up. If we make sure value is an empty string at
this point, we should fix the problem.

This seems to work OK, and is the fix I've gone for.

2. Handle a NULL string in make_bare_word and make_word_flags.

This also works, and is low risk, although it could affect performance I
suppose... this code is probably on a lot more code paths.


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


pushd does not ignore -option after --

2005-11-14 Thread Ateeq A Altaf
Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: i386-redhat-linux-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib
-D_FILE_OFFSET_BITS=64 -O2 -g -pipe -m32 -march=i386 -mtune=pentium4
uname output: Linux firewall.hydrosoft 2.6.11-1.35_FC3 #1 Mon Jun 13
00:52:08 EDT 2005 i686 i686 i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu

Bash Version: 3.0
Patch Level: 14
Release Status: release

Description:
pushd should accept dirs beginning with - e.g. "-test-dir-" by using
pushd -- -test-dir-, this does not work:

[EMAIL PROTECTED] ~]# pushd -- -a
bash: pushd: -a: invalid number
pushd: usage: pushd [dir | +N | -N] [-n]

Repeat-By:
mkdir -- "-test-dir-";
pushd -- -test-dir-




___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: How to call a new bash function within a makefile

2005-11-14 Thread OnMyWayHome

Thanks for the post Paul. I may be remembering it incorrectly,
but your post does help me.
Thanks,
Chris

Paul D. Smith wrote:

%% OnMyWayHome <[EMAIL PROTECTED]> writes:

  o> I don't have gnu.bash on my newsgroup server, so I'm posting this here.
  o> Here is an example GNU makefile:

  o> function DoThis()
  o> {
  o>  echo $0
  o> }

  o> all :
  o>  DoThis "Test"

  o> I've seen this done before where a bash function is defined within a
  o> makefile, and can be subsequently called when a target is matched.

You must have been imagining things :-)

This is not, and never has been supported.  At least, not in GNU make.
Makefiles must contain make syntax.  They cannot contain shell
functions.


I mean, I guess you could do something like this:

defineDoThis = function DoThis() { echo $0; }

all:
$(defineDoThis); DoThis "Test"

but I doubt that's what you're looking for.




___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash