CVS commit: [netbsd-6] src/external/historical/nawk/dist

2013-03-14 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Mar 14 15:54:58 UTC 2013

Modified Files:
src/external/historical/nawk/dist [netbsd-6]: tran.c

Log Message:
Pull up following revision(s) (requested by cheusov in ticket #836):
external/historical/nawk/dist/tran.c: revision 1.8
PR/47553: Aleksev Cheusov: awk segfault: NULL dereference.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.5.6.1 src/external/historical/nawk/dist/tran.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.5 src/external/historical/nawk/dist/tran.c:1.5.6.1
--- src/external/historical/nawk/dist/tran.c:1.5	Sat May 28 15:13:04 2011
+++ src/external/historical/nawk/dist/tran.c	Thu Mar 14 15:54:58 2013
@@ -344,7 +344,7 @@ char *setsval(Cell *vp, const char *s)	/
 		donefld = 0;	/* mark $1... invalid */
 		donerec = 1;
 	}
-	t = tostring(s);	/* in case it's self-assign */
+	t = s ? tostring(s) : tostring();	/* in case it's self-assign */
 	if (freeable(vp))
 		xfree(vp-sval);
 	vp-tval = ~NUM;



CVS commit: [netbsd-6] src/external/historical/nawk/dist

2012-07-12 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Jul 12 19:24:21 UTC 2012

Modified Files:
src/external/historical/nawk/dist [netbsd-6]: b.c lib.c main.c proto.h
run.c

Log Message:
Pull up following revision(s) (requested by christos in ticket #414):

external/historical/nawk/dist/main.cpatch
external/historical/nawk/dist/b.c   patch
external/historical/nawk/dist/lib.c patch
external/historical/nawk/dist/proto.h   patch
external/historical/nawk/dist/run.c patch

Fix segfault in awk, and address PR#46155.
[christos, ticket #414]


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.8.1 src/external/historical/nawk/dist/b.c
cvs rdiff -u -r1.4 -r1.4.6.1 src/external/historical/nawk/dist/lib.c
cvs rdiff -u -r1.6 -r1.6.4.1 src/external/historical/nawk/dist/main.c
cvs rdiff -u -r1.5 -r1.5.4.1 src/external/historical/nawk/dist/proto.h
cvs rdiff -u -r1.4 -r1.4.2.1 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/b.c
diff -u src/external/historical/nawk/dist/b.c:1.2 src/external/historical/nawk/dist/b.c:1.2.8.1
--- src/external/historical/nawk/dist/b.c:1.2	Thu Aug 26 14:55:19 2010
+++ src/external/historical/nawk/dist/b.c	Thu Jul 12 19:24:21 2012
@@ -624,6 +624,96 @@ int nematch(fa *f, const char *p0)	/* no
 	return (0);
 }
 
+
+/*
+ * NAME
+ * fnematch
+ *
+ * DESCRIPTION
+ * A stream-fed version of nematch which transfers characters to a
+ * null-terminated buffer. All characters up to and including the last
+ * character of the matching text or EOF are placed in the buffer. If
+ * a match is found, patbeg and patlen are set appropriately.
+ *
+ * RETURN VALUES
+ * 0No match found.
+ * 1Match found.
+ */  
+
+int fnematch(fa *pfa, FILE *f, uschar **pbuf, int *pbufsize, int quantum)	
+{
+	uschar *buf = *pbuf;
+	int bufsize = *pbufsize;
+	int c, i, j, k, ns, s;
+
+	s = pfa-initstat;
+	assert(s  pfa-state_count);
+	patlen = 0;
+
+	/*
+	 * All indices relative to buf.
+	 * i = j = k = bufsize
+	 *
+	 * i: origin of active substring
+	 * j: current character
+	 * k: destination of next getc()
+	 */
+	i = -1, k = 0;
+do {
+		j = i++;
+		do {
+			if (++j == k) {
+if (k == bufsize)
+	if (!adjbuf(buf, bufsize, bufsize+1, quantum, 0, fnematch))
+		FATAL(stream '%.30s...' too long, buf);	
+buf[k++] = (c = getc(f)) != EOF ? c : 0;
+			}
+			c = buf[j];
+			/* assert(c  NCHARS); */
+
+			if ((ns = pfa-gototab[s][c]) != 0)
+s = ns;
+			else
+s = cgoto(pfa, s, c);
+			assert(s  pfa-state_count);
+
+			if (pfa-out[s]) {	/* final state */
+patlen = j - i + 1;
+if (c == 0)	/* don't count $ */
+	patlen--;
+			}
+		} while (buf[j]  s != 1);
+		s = 2;
+	} while (buf[i]  !patlen);
+
+	/* adjbuf() may have relocated a resized buffer. Inform the world. */
+	*pbuf = buf;
+	*pbufsize = bufsize;
+
+	if (patlen) {
+		patbeg = buf + i;
+		/*
+		 * Under no circumstances is the last character fed to
+		 * the automaton part of the match. It is EOF's nullbyte,
+		 * or it sent the automaton into a state with no further
+		 * transitions available (s==1), or both. Room for a
+		 * terminating nullbyte is guaranteed.
+		 *
+		 * ungetc any chars after the end of matching text
+		 * (except for EOF's nullbyte, if present) and null
+		 * terminate the buffer.
+		 */
+		do
+			if (buf[--k]  ungetc(buf[k], f) == EOF)
+FATAL(unable to ungetc '%c', buf[k]);	
+		while (k  i + patlen);
+		buf[k] = 0;
+		return 1;
+	}
+	else
+		return 0;
+}
+
 Node *reparse(const char *p)	/* parses regular expression pointed to by p */
 {			/* uses relex() to scan regular expression */
 	Node *np;

Index: src/external/historical/nawk/dist/lib.c
diff -u src/external/historical/nawk/dist/lib.c:1.4 src/external/historical/nawk/dist/lib.c:1.4.6.1
--- src/external/historical/nawk/dist/lib.c:1.4	Thu Jan 20 21:23:11 2011
+++ src/external/historical/nawk/dist/lib.c	Thu Jul 12 19:24:21 2012
@@ -38,6 +38,7 @@ THIS SOFTWARE.
 
 char	EMPTY[] = { '\0' };
 FILE	*infile	= NULL;
+int	innew;		/* 1 = infile has not been read by readrec */
 char	*file	= EMPTY;
 uschar	*record;
 int	recsize	= RECSIZE;
@@ -104,6 +105,7 @@ void initgetrec(void)
 		argno++;
 	}
 	infile = stdin;		/* no filenames, so use stdin */
+	innew = 1;
 }
 
 static int firsttime = 1;
@@ -146,9 +148,12 @@ int getrec(uschar **pbuf, int *pbufsize,
 infile = stdin;
 			else if ((infile = fopen(file, r)) == NULL)
 FATAL(can't open file %s, file);
+			innew = 1;
 			setfval(fnrloc, 0.0);
 		}
-		c = readrec(buf, bufsize, infile);
+		c = readrec(buf, bufsize, infile, innew);
+		if (innew)
+			innew = 0;
 		if (c != 0 || buf[0] != '\0') {	/* normal record */
 			if (isrecord) {
 if (freeable(fldtab[0]))
@@ -186,9 +191,9 @@ void nextfile(void)
 	argno++;
 }
 
-int