diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-07 20:01:39 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-07 20:01:39 +0200 |
commit | f65c5f5c547c48b7766db58d10043a504d953aa1 (patch) | |
tree | 3cb8bd1fe617ee5664da918e3bebb808d6c8cf44 | |
parent | e8f36330d9bb27f9f7e66aa6f01ff92c07d86f62 (diff) | |
download | busybox-w32-f65c5f5c547c48b7766db58d10043a504d953aa1.tar.gz busybox-w32-f65c5f5c547c48b7766db58d10043a504d953aa1.tar.bz2 busybox-w32-f65c5f5c547c48b7766db58d10043a504d953aa1.zip |
awk: next_input_file can return NULL, don't SEGV in this case.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/editors/awk.c b/editors/awk.c index 7685546e5..0918026d7 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -2627,7 +2627,7 @@ static var *evaluate(node *op, var *res) | |||
2627 | rsm = iF; | 2627 | rsm = iF; |
2628 | } | 2628 | } |
2629 | 2629 | ||
2630 | if (!rsm->F) { | 2630 | if (!rsm || !rsm->F) { |
2631 | setvar_i(intvar[ERRNO], errno); | 2631 | setvar_i(intvar[ERRNO], errno); |
2632 | setvar_i(res, -1); | 2632 | setvar_i(res, -1); |
2633 | break; | 2633 | break; |
@@ -2961,7 +2961,7 @@ static rstream *next_input_file(void) | |||
2961 | #define rsm (G.next_input_file__rsm) | 2961 | #define rsm (G.next_input_file__rsm) |
2962 | #define files_happen (G.next_input_file__files_happen) | 2962 | #define files_happen (G.next_input_file__files_happen) |
2963 | 2963 | ||
2964 | FILE *F = NULL; | 2964 | FILE *F; |
2965 | const char *fname, *ind; | 2965 | const char *fname, *ind; |
2966 | 2966 | ||
2967 | if (rsm.F) | 2967 | if (rsm.F) |
@@ -2969,19 +2969,21 @@ static rstream *next_input_file(void) | |||
2969 | rsm.F = NULL; | 2969 | rsm.F = NULL; |
2970 | rsm.pos = rsm.adv = 0; | 2970 | rsm.pos = rsm.adv = 0; |
2971 | 2971 | ||
2972 | do { | 2972 | for (;;) { |
2973 | if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) { | 2973 | if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) { |
2974 | if (files_happen) | 2974 | if (files_happen) |
2975 | return NULL; | 2975 | return NULL; |
2976 | fname = "-"; | 2976 | fname = "-"; |
2977 | F = stdin; | 2977 | F = stdin; |
2978 | } else { | 2978 | break; |
2979 | ind = getvar_s(incvar(intvar[ARGIND])); | ||
2980 | fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind)); | ||
2981 | if (fname && *fname && !is_assignment(fname)) | ||
2982 | F = xfopen_stdin(fname); | ||
2983 | } | 2979 | } |
2984 | } while (!F); | 2980 | ind = getvar_s(incvar(intvar[ARGIND])); |
2981 | fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind)); | ||
2982 | if (fname && *fname && !is_assignment(fname)) { | ||
2983 | F = xfopen_stdin(fname); | ||
2984 | break; | ||
2985 | } | ||
2986 | } | ||
2985 | 2987 | ||
2986 | files_happen = TRUE; | 2988 | files_happen = TRUE; |
2987 | setvar_s(intvar[FILENAME], fname); | 2989 | setvar_s(intvar[FILENAME], fname); |