diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-09 14:15:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-09 14:15:57 +0000 |
commit | 1943aec2ec390d9fda159aa0412362780ec83f09 (patch) | |
tree | ec9ddd365d2232d9fb621b79000cbf20f1410cda /shell/hush.c | |
parent | efea9d2819165b414b81a47c8227ae007bd5382a (diff) | |
download | busybox-w32-1943aec2ec390d9fda159aa0412362780ec83f09.tar.gz busybox-w32-1943aec2ec390d9fda159aa0412362780ec83f09.tar.bz2 busybox-w32-1943aec2ec390d9fda159aa0412362780ec83f09.zip |
hush: plug the leak of expanded heredoc
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c index d791b62d0..4c2716ddd 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -64,7 +64,6 @@ | |||
64 | * | 64 | * |
65 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 65 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
66 | */ | 66 | */ |
67 | |||
68 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ | 67 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ |
69 | //TODO: pull in some .h and find out whether we have SINGLE_APPLET_MAIN? | 68 | //TODO: pull in some .h and find out whether we have SINGLE_APPLET_MAIN? |
70 | //#include "applet_tables.h" doesn't work | 69 | //#include "applet_tables.h" doesn't work |
@@ -79,6 +78,12 @@ | |||
79 | # define PIPE_BUF 4096 /* amount of buffering in a pipe */ | 78 | # define PIPE_BUF 4096 /* amount of buffering in a pipe */ |
80 | #endif | 79 | #endif |
81 | 80 | ||
81 | |||
82 | /* Debug build knobs */ | ||
83 | //#define LEAK_HUNTING 1 | ||
84 | //#define WANT_TO_TEST_NOMMU 1 | ||
85 | |||
86 | |||
82 | #ifdef WANT_TO_TEST_NOMMU | 87 | #ifdef WANT_TO_TEST_NOMMU |
83 | # undef BB_MMU | 88 | # undef BB_MMU |
84 | # undef USE_FOR_NOMMU | 89 | # undef USE_FOR_NOMMU |
@@ -214,8 +219,7 @@ static void debug_print_strings(const char *prefix, char **vv) | |||
214 | /* | 219 | /* |
215 | * Leak hunting. Use hush_leaktool.sh for post-processing. | 220 | * Leak hunting. Use hush_leaktool.sh for post-processing. |
216 | */ | 221 | */ |
217 | //#define FOR_HUSH_LEAKTOOL | 222 | #ifdef LEAK_HUNTING |
218 | #ifdef FOR_HUSH_LEAKTOOL | ||
219 | static void *xxmalloc(int lineno, size_t size) | 223 | static void *xxmalloc(int lineno, size_t size) |
220 | { | 224 | { |
221 | void *ptr = xmalloc((size + 0xff) & ~0xff); | 225 | void *ptr = xmalloc((size + 0xff) & ~0xff); |
@@ -743,7 +747,7 @@ static char **add_strings_to_strings(char **strings, char **add, int need_to_dup | |||
743 | v[count1 + i] = (need_to_dup ? xstrdup(add[i]) : add[i]); | 747 | v[count1 + i] = (need_to_dup ? xstrdup(add[i]) : add[i]); |
744 | return v; | 748 | return v; |
745 | } | 749 | } |
746 | #ifdef FOR_HUSH_LEAKTOOL | 750 | #ifdef LEAK_HUNTING |
747 | static char **xx_add_strings_to_strings(int lineno, char **strings, char **add, int need_to_dup) | 751 | static char **xx_add_strings_to_strings(int lineno, char **strings, char **add, int need_to_dup) |
748 | { | 752 | { |
749 | char **ptr = add_strings_to_strings(strings, add, need_to_dup); | 753 | char **ptr = add_strings_to_strings(strings, add, need_to_dup); |
@@ -761,7 +765,7 @@ static char **add_string_to_strings(char **strings, char *add) | |||
761 | v[1] = NULL; | 765 | v[1] = NULL; |
762 | return add_strings_to_strings(strings, v, /*dup:*/ 0); | 766 | return add_strings_to_strings(strings, v, /*dup:*/ 0); |
763 | } | 767 | } |
764 | #ifdef FOR_HUSH_LEAKTOOL | 768 | #ifdef LEAK_HUNTING |
765 | static char **xx_add_string_to_strings(int lineno, char **strings, char *add) | 769 | static char **xx_add_string_to_strings(int lineno, char **strings, char *add) |
766 | { | 770 | { |
767 | char **ptr = add_string_to_strings(strings, add); | 771 | char **ptr = add_string_to_strings(strings, add); |
@@ -2310,6 +2314,7 @@ static void setup_heredoc(struct redir_struct *redir) | |||
2310 | len -= written; | 2314 | len -= written; |
2311 | if (len == 0) { | 2315 | if (len == 0) { |
2312 | close(pair.wr); | 2316 | close(pair.wr); |
2317 | free(expanded); | ||
2313 | return; | 2318 | return; |
2314 | } | 2319 | } |
2315 | heredoc += written; | 2320 | heredoc += written; |