aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--awkgram.c9
-rw-r--r--awkgram.y9
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am5
-rw-r--r--test/Makefile.in10
-rw-r--r--test/Maketests5
-rw-r--r--test/readbuf.awk2
-rw-r--r--test/readbuf.ok3
9 files changed, 45 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index a23e23a3..4eea7fd9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-11 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awkgram.y (yylex): Fix invalid read problems.
+ Reported by Hanno Boeck <hanno@hboeck.de>.
+
2015-10-04 Arnold D. Robbins <arnold@skeeve.com>
* configure.ac: Bump version to 4.1.3a.
diff --git a/awkgram.c b/awkgram.c
index 9ced0daf..845dbbef 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -142,8 +142,8 @@ const char *const ruletab[] = {
static bool in_print = false; /* lexical scanning kludge for print */
static int in_parens = 0; /* lexical scanning kludge for print */
static int sub_counter = 0; /* array dimension counter for use in delete */
-static char *lexptr = NULL; /* pointer to next char during parsing */
-static char *lexend;
+static char *lexptr; /* pointer to next char during parsing */
+static char *lexend; /* end of buffer */
static char *lexptr_begin; /* keep track of where we were for error msgs */
static char *lexeme; /* beginning of lexeme for debugging */
static bool lexeof; /* seen EOF for current source? */
@@ -4450,7 +4450,8 @@ yyerror(const char *m, ...)
if (thisline == NULL) {
cp = lexeme;
if (*cp == '\n') {
- cp--;
+ if (cp > lexptr_begin)
+ cp--;
mesg = _("unexpected newline or end of string");
}
for (; cp != lexptr_begin && *cp != '\n'; --cp)
@@ -4461,6 +4462,8 @@ yyerror(const char *m, ...)
}
/* NL isn't guaranteed */
bp = lexeme;
+ if (bp < thisline)
+ bp = thisline + 1;
while (bp < lexend && *bp && *bp != '\n')
bp++;
} else {
diff --git a/awkgram.y b/awkgram.y
index cb41cf3b..11771609 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -102,8 +102,8 @@ const char *const ruletab[] = {
static bool in_print = false; /* lexical scanning kludge for print */
static int in_parens = 0; /* lexical scanning kludge for print */
static int sub_counter = 0; /* array dimension counter for use in delete */
-static char *lexptr = NULL; /* pointer to next char during parsing */
-static char *lexend;
+static char *lexptr; /* pointer to next char during parsing */
+static char *lexend; /* end of buffer */
static char *lexptr_begin; /* keep track of where we were for error msgs */
static char *lexeme; /* beginning of lexeme for debugging */
static bool lexeof; /* seen EOF for current source? */
@@ -2111,7 +2111,8 @@ yyerror(const char *m, ...)
if (thisline == NULL) {
cp = lexeme;
if (*cp == '\n') {
- cp--;
+ if (cp > lexptr_begin)
+ cp--;
mesg = _("unexpected newline or end of string");
}
for (; cp != lexptr_begin && *cp != '\n'; --cp)
@@ -2122,6 +2123,8 @@ yyerror(const char *m, ...)
}
/* NL isn't guaranteed */
bp = lexeme;
+ if (bp < thisline)
+ bp = thisline + 1;
while (bp < lexend && *bp && *bp != '\n')
bp++;
} else {
diff --git a/test/ChangeLog b/test/ChangeLog
index 2199f56c..8792af95 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-11 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (readbuf): New test.
+ * readbuf.awk, readbuf.ok: New files.
+
2015-09-26 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (muldimposix): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index 56fd5da9..0d8658a0 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -760,6 +760,8 @@ EXTRA_DIST = \
range1.awk \
range1.in \
range1.ok \
+ readbuf.awk \
+ readbuf.ok \
readdir.awk \
readdir0.awk \
readfile2.awk \
@@ -1044,7 +1046,8 @@ BASIC_TESTS = \
paramdup paramres paramtyp paramuninitglobal parse1 parsefld parseme \
pcntplus posix2008sub prdupval prec printf0 printf1 prmarscl prmreuse \
prt1eval prtoeval \
- rand range1 rebrackloc rebt8b1 redfilnm regeq regexpbrack regexpbrack2 \
+ rand range1 readbuf rebrackloc rebt8b1 redfilnm \
+ regeq regexpbrack regexpbrack2 \
regexprange regrange reindops \
reparse resplit rri1 rs rsnul1nl rsnulbig rsnulbig2 rstest1 rstest2 \
rstest3 rstest4 rstest5 rswhite \
diff --git a/test/Makefile.in b/test/Makefile.in
index 7963cfbb..7917fc2d 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1017,6 +1017,8 @@ EXTRA_DIST = \
range1.awk \
range1.in \
range1.ok \
+ readbuf.awk \
+ readbuf.ok \
readdir.awk \
readdir0.awk \
readfile2.awk \
@@ -1300,7 +1302,8 @@ BASIC_TESTS = \
paramdup paramres paramtyp paramuninitglobal parse1 parsefld parseme \
pcntplus posix2008sub prdupval prec printf0 printf1 prmarscl prmreuse \
prt1eval prtoeval \
- rand range1 rebrackloc rebt8b1 redfilnm regeq regexpbrack regexpbrack2 \
+ rand range1 readbuf rebrackloc rebt8b1 redfilnm \
+ regeq regexpbrack regexpbrack2 \
regexprange regrange reindops \
reparse resplit rri1 rs rsnul1nl rsnulbig rsnulbig2 rstest1 rstest2 \
rstest3 rstest4 rstest5 rswhite \
@@ -3238,6 +3241,11 @@ range1:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+readbuf:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
rebrackloc:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 7c55a443..1723c33f 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -702,6 +702,11 @@ range1:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+readbuf:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
rebrackloc:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/readbuf.awk b/test/readbuf.awk
new file mode 100644
index 00000000..b7512db4
--- /dev/null
+++ b/test/readbuf.awk
@@ -0,0 +1,2 @@
+
+{
diff --git a/test/readbuf.ok b/test/readbuf.ok
new file mode 100644
index 00000000..110a26bc
--- /dev/null
+++ b/test/readbuf.ok
@@ -0,0 +1,3 @@
+gawk: readbuf.awk:2: {
+gawk: readbuf.awk:2: ^ unexpected newline or end of string
+EXIT CODE: 1