Patch from David Daney:
[oweals/busybox.git] / editors / awk.c
index 9905be092a0775c64f369cf22137f7fe5a494d68..c1cb2a2e26febff7f46332ad2ca311359aaa5eac 100644 (file)
@@ -1211,6 +1211,7 @@ static void chain_group(void) {
 
        if (c & TC_GRPSTART) {
                while(next_token(TC_GRPSEQ | TC_GRPTERM) != TC_GRPTERM) {
+                       if (t.tclass & TC_NEWLINE) continue;    
                        rollback_token();
                        chain_group();
                }
@@ -1553,7 +1554,7 @@ static void handle_special(var *v) {
                        memcpy(b+len, s, l);
                        len += l;
                }
-               b[len] = '\0';
+               if (b) b[len] = '\0';
                setvar_p(V[F0], b);
                is_f0_split = TRUE;
 
@@ -2550,6 +2551,7 @@ static int awk_exit(int r) {
 
        if (! exiting) {
                exiting = TRUE;
+               nextrec = FALSE;
                evaluate(endseq.first, &tv);
        }
 
@@ -2669,8 +2671,12 @@ extern int awk_main(int argc, char **argv) {
        for (envp=environ; *envp; envp++) {
                s = bb_xstrdup(*envp);
                s1 = strchr(s, '=');
+               if (!s1) {
+                       goto keep_going;
+               }
                *(s1++) = '\0';
                setvar_u(findvar(iamarray(V[ENVIRON]), s), s1);
+keep_going:
                free(s);
        }