diff options
author | Denys Vlasenko | 2011-09-07 20:01:39 +0200 |
---|---|---|
committer | Denys Vlasenko | 2011-09-07 20:01:39 +0200 |
commit | f65c5f5c547c48b7766db58d10043a504d953aa1 (patch) | |
tree | 3cb8bd1fe617ee5664da918e3bebb808d6c8cf44 | |
parent | e8f36330d9bb27f9f7e66aa6f01ff92c07d86f62 (diff) | |
download | busybox-f65c5f5c547c48b7766db58d10043a504d953aa1.zip busybox-f65c5f5c547c48b7766db58d10043a504d953aa1.tar.gz |
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 7685546..0918026 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2627,7 +2627,7 @@ static var *evaluate(node *op, var *res) rsm = iF; } - if (!rsm->F) { + if (!rsm || !rsm->F) { setvar_i(intvar[ERRNO], errno); setvar_i(res, -1); break; @@ -2961,7 +2961,7 @@ static rstream *next_input_file(void) #define rsm (G.next_input_file__rsm) #define files_happen (G.next_input_file__files_happen) - FILE *F = NULL; + FILE *F; const char *fname, *ind; if (rsm.F) @@ -2969,19 +2969,21 @@ static rstream *next_input_file(void) rsm.F = NULL; rsm.pos = rsm.adv = 0; - do { + for (;;) { if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) { if (files_happen) return NULL; fname = "-"; F = stdin; - } else { - ind = getvar_s(incvar(intvar[ARGIND])); - fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind)); - if (fname && *fname && !is_assignment(fname)) - F = xfopen_stdin(fname); + break; } - } while (!F); + ind = getvar_s(incvar(intvar[ARGIND])); + fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind)); + if (fname && *fname && !is_assignment(fname)) { + F = xfopen_stdin(fname); + break; + } + } files_happen = TRUE; setvar_s(intvar[FILENAME], fname); |