Re: Inconsistent output in terminal emulator

2009-08-25 Thread Ralf Goertz
Mike Stroyan wrote:

> On Mon, Aug 24, 2009 at 09:44:36AM +0200, Ralf Goertz wrote:
>> I hope you don't mind my jumping in with a question that is only
>> remotely related. But since you guys seem to be experts on tty…
>> 
>> I have an embedded device running a linux kernel that uses a serial
>> port as console (console=ttyAS0,115200). I can log on to that device
>> via telnet. Is it possible to see what is written to that console from
>> within the telnet session using features provided by the shell?
> 
> It is very likely that an embedded device is using busybox as the shell
> rather than bash.  That would be good news for you as there is a
> setconsole builtin for busybox that will redirect console output to a
> different device such as the telnet pty.  Bash does not include
> console redirection. Busybox may be built with or without the
> setconsole feature.  See the http://man-wiki.net/index.php/1:busybox
> manual and check the details of your device.

Ah, great, there is indeed a setconsole on my device.

Thanks,

Ralf


unset associative array may cause segfault

2009-08-25 Thread Roman Rakus

reproducer:
declare -A aaa
aaa='somestring'
unset aaa

This commands cause segmentation fault, free unallocated memory.
Chet do you already fix it? Here is my fast patch.
RR
diff -up bash-4.0/hashlib.c.alloc bash-4.0/hashlib.c
--- bash-4.0/hashlib.c.alloc2009-08-25 16:25:21.0 +0200
+++ bash-4.0/hashlib.c  2009-08-25 16:25:52.0 +0200
@@ -193,7 +193,7 @@ hash_search (string, table, flags)
   table->bucket_array[bucket] = list;
 
   list->data = NULL;
-  list->key = (char *)string;  /* XXX fix later */
+  list->key = (char *)savestring (string); /* XXX fix later */
   list->khash = hv;
   list->times_found = 0;
 


Re: unset associative array may cause segfault

2009-08-25 Thread Chet Ramey
Roman Rakus wrote:
> reproducer:
> declare -A aaa
> aaa='somestring'
> unset aaa
> 
> This commands cause segmentation fault, free unallocated memory.
> Chet do you already fix it? Here is my fast patch.

I already fixed it, thanks.  Your patch introduces large memory leaks;
the right place to fix it is where the code passes a literal string to
assoc_insert().

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/




Re: unset associative array may cause segfault

2009-08-25 Thread Roman Rakus

On 08/25/2009 04:47 PM, Chet Ramey wrote:

Roman Rakus wrote:
   

reproducer:
declare -A aaa
aaa='somestring'
unset aaa

This commands cause segmentation fault, free unallocated memory.
Chet do you already fix it? Here is my fast patch.
 


I already fixed it, thanks.  Your patch introduces large memory leaks;
the right place to fix it is where the code passes a literal string to
assoc_insert().

Chet

   
Nice, thanks. This fix (and others) will be in other round of patches 
for bash-4.0 or in bash-4.1 or in bash-5.0 or...?

RR


Re: unset associative array may cause segfault

2009-08-25 Thread Chet Ramey
> >> reproducer:
> >> declare -A aaa
> >> aaa='somestring'
> >> unset aaa
> >>
> >> This commands cause segmentation fault, free unallocated memory.
> >> Chet do you already fix it? Here is my fast patch.
> >>  
> >
> > I already fixed it, thanks.  Your patch introduces large memory leaks;
> > the right place to fix it is where the code passes a literal string to
> > assoc_insert().
> >
> Nice, thanks. This fix (and others) will be in other round of patches 
> for bash-4.0 or in bash-4.1 or in bash-5.0 or...?

It will probably be a patch for bash-4.0, and will certainly be in bash-4.1.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/




Re: unset associative array may cause segfault

2009-08-25 Thread Chris F.A. Johnson
On Tue, 25 Aug 2009, Chet Ramey wrote:

> Roman Rakus wrote:
> > reproducer:
> > declare -A aaa
> > aaa='somestring'
> > unset aaa
> > 
> > This commands cause segmentation fault, free unallocated memory.
> > Chet do you already fix it? Here is my fast patch.
> 
> I already fixed it, thanks.

Do you have a patch for it? It's not fixed with the patches posted so far.


-- 
   Chris F.A. Johnson, webmaster 
   ===
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)




Re: unset associative array may cause segfault

2009-08-25 Thread Chet Ramey
Chris F.A. Johnson wrote:
> On Tue, 25 Aug 2009, Chet Ramey wrote:
> 
>> Roman Rakus wrote:
>>> reproducer:
>>> declare -A aaa
>>> aaa='somestring'
>>> unset aaa
>>>
>>> This commands cause segmentation fault, free unallocated memory.
>>> Chet do you already fix it? Here is my fast patch.
>> I already fixed it, thanks.
> 
> Do you have a patch for it? It's not fixed with the patches posted so far.

For Pete's sake, I just fixed it last night.  It will be in the next
round of patches.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/




wget command with simple url makes bash crash

2009-08-25 Thread Oskar Hermansson
Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2
-Wall
uname output: Linux oshe-laptop 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18
18:40:08 UTC 2009 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.2
Patch Level: 48
Release Status: release

Description:
bash crashes when running the following wget command for downloading a
file:
wget
http://www.kohanaphp.com/download?modules%5Bauth%5D=Auth&vendors%5Bmarkdown%5D=Markdown&languages%5Ben_US%5D=en_US&format=zip

If the command is placed in a file instead, the file is successfully
downloaded:
wget `cat url.txt`

The first wget command does not make for example "sh" crash.

My wget version (if relevant): GNU Wget 1.11.4

Repeat-By:
1. wget
http://www.kohanaphp.com/download?modules%5Bauth%5D=Auth&vendors%5Bmarkdown%5D=Markdown&languages%5Ben_US%5D=en_US&format=zip
2. bash crashes

Oskar


Re: bug or undocumented feature

2009-08-25 Thread mitch
On Aug 22, 11:17 am, Jan Schampera  wrote:
> Mitch Frazier wrote:
> > The close appears to be a special case of (from the man page):
>
> >> Similarly, the redirection operator
>
> >>       [n]>&digit-
>
> >> moves the file descriptor digit to file descriptor n,
> >> or the standard output (file descriptor 1) if n is not
> >> specified.
>
> > Not sure if that's a bug or a feature but it should be a feature and
> > probably should be documented.
>
> It's not a bug. It's not undocumented per se, it's in the description of
> the corresponding input duplication mechanism. It applies to both
> duplication methods.
>
> Jan

Yep, I see that now.  I should RTFM :)


Re: Inconsistent output in terminal emulator

2009-08-25 Thread nico raffo
On Sat, Aug 22, 2009 at 5:30 PM, Chet Ramey  wrote:
>
> Bob Proulx wrote:
> > nico raffo wrote:
> >> I'm writing a simple terminal emulator (on linux using standard pty
> >> libraries) and have run across some behavior in bash that I cannot
> >> explain after several weeks of reading documentation.
> >
> > I am not sure of the exact cause of your trouble.  But having been a
> > few days and no one else suggesting anything I thought I would jump in
> > anyway.
> >
> > Hopefully you will be using a free license on your code?  And then you
> > could post it and perhaps someone might see something in it then.
> >
> >> However with bash, the shell doesn't respond at all until a
> >>  is sent, and then bash only sends the output of the command, not
> >> the command itself. If my terminal emulator is expecting the shell to
> >> provide all display text, it wouldn't show the commands at all.
> >
> > This seems like you are tripping into the difference between different
> > tty driver settings of raw mode and canonical input mode (aka cooked
> > mode).
>
> I think it's how the terminal emulator sets the ECHO flag in the
> termios local status word (c_lflag & ECHO).  If that bit is set,
> readline echoes the text it reads back to the terminal.  If it's
> not, readline assumes that the terminal is in no-echo mode and that
> it should not echo the characters.
>
> I assume that the difference between bash and zsh is that zsh sets
> the ECHO bit and leaves it set when it exits.  A subsequent invocation
> of bash picks up that flag and echoes input as a result.
>
> Chet

Thanks for pointing me in the right direction. The ECHO flag did the trick.

Nico




Re: wget command with simple url makes bash crash

2009-08-25 Thread Chet Ramey
Oskar Hermansson wrote:

> Bash Version: 3.2
> Patch Level: 48
> Release Status: release
> 
> Description:
> bash crashes when running the following wget command for downloading a
> file:
> wget
> http://www.kohanaphp.com/download?modules%5Bauth%5D=Auth&vendors%5Bmarkdown%5D=Markdown&languages%5Ben_US%5D=en_US&format=zip
> 
> If the command is placed in a file instead, the file is successfully
> downloaded:
> wget `cat url.txt`
> 
> The first wget command does not make for example "sh" crash.
> 
> My wget version (if relevant): GNU Wget 1.11.4
> 
> Repeat-By:
> 1. wget
> http://www.kohanaphp.com/download?modules%5Bauth%5D=Auth&vendors%5Bmarkdown%5D=Markdown&languages%5Ben_US%5D=en_US&format=zip
> 2. bash crashes

How does bash crash?  Does it exit on a fatal signal, or dump core?
You're running three commands here, since the URL is unquoted and
contains two `&' characters.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/