[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bash Segmentation fault using Here Strings
From: |
Stroesser, Bodo |
Subject: |
bash Segmentation fault using Here Strings |
Date: |
Wed, 24 Sep 2003 17:44:51 +0200 |
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g -O2
uname output: Linux s390develop 2.4.19-64GB-SMP #5 SMP Mit Jul 23 14:27:20 CEST
2003 i686 unknown
Machine Type: i686-pc-linux-gnu
Bash Version: 2.05b
Patch Level: 0
Release Status: release
Description:
[ If the execution of a command, that produces no output is
the input to a Here String, bash seg-faults]
Repeat-By:
[Example: "cat <<< $(echo -n)" causes a Segmentation fault]
Fix:
[In the described case, the result of
expand_string_to_string(), called from write_here_string() in
file redir.c, is NULL. This case is not checked and
strlen() for the result is called --> Segfault. The following
patch works:
--- redir.c.old Wed Sep 24 16:57:33 2003
+++ redir.c Wed Sep 24 17:00:20 2003
@@ -263,16 +263,18 @@
int herelen, n, e;
herestr = expand_string_to_string (redirectee->word, 0);
- herelen = strlen (herestr);
-
- n = write (fd, herestr, herelen);
- if (n == herelen)
+ if ( herestr )
+ {
+ herelen = strlen (herestr);
+ n = write (fd, herestr, herelen);
+ free (herestr);
+ }
+ if (n == herelen || ! herestr)
{
n = write (fd, "\n", 1);
herelen = 1;
}
e = errno;
- free (herestr);
if (n != herelen)
{
if (e == 0)
]
Best regards
Bodo Stroesser
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bash Segmentation fault using Here Strings,
Stroesser, Bodo <=