changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: awk: fix nextfile crash (thanks leetspete)

changeset 7167: e4a7fe526ec5
parent 7166: b1bd262dc055
child 7168: 1a2f7f23c5bd
author: cinap_lenrek@felloff.net
date: Tue, 16 Apr 2019 16:13:30 +0200
files: sys/src/cmd/awk/lib.c
description: awk: fix nextfile crash (thanks leetspete)

to reproduce the bug:

term% awk 'BEGIN{nextfile; nextfile;}'
sys: trap: fault read addr=0x10 pc=0x00019a3a
awk 6584: suicide: sys: trap: fault read addr=0x10 pc=0x00019a3a
     1.1--- a/sys/src/cmd/awk/lib.c
     1.2+++ b/sys/src/cmd/awk/lib.c
     1.3@@ -155,10 +155,7 @@ int getrec(char **pbuf, int *pbufsize, i
     1.4 			return 1;
     1.5 		}
     1.6 		/* Beof arrived on this file; set up next */
     1.7-		if (infile != &stdin)
     1.8-			Bterm(infile);
     1.9-		infile = nil;
    1.10-		argno++;
    1.11+		nextfile();
    1.12 	}
    1.13 	*pbuf = buf;
    1.14 	*pbufsize = bufsize;
    1.15@@ -167,7 +164,7 @@ int getrec(char **pbuf, int *pbufsize, i
    1.16 
    1.17 void nextfile(void)
    1.18 {
    1.19-	if (infile != &stdin)
    1.20+	if (infile != nil && infile != &stdin)
    1.21 		Bterm(infile);
    1.22 	infile = nil;
    1.23 	argno++;