From b90d6abb81f54bec11305d5091532c8d5fc47a18 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 28 Oct 2015 21:21:05 +0200 Subject: Disallow nul bytes in source code no matter what. --- ChangeLog | 5 +++++ awkgram.c | 4 ++-- awkgram.y | 4 ++-- test/ChangeLog | 5 +++++ test/Makefile.am | 4 +++- test/Makefile.in | 9 ++++++++- test/Maketests | 5 +++++ test/nulinsrc.awk | Bin 0 -> 3 bytes test/nulinsrc.ok | 2 ++ 9 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 test/nulinsrc.awk create mode 100644 test/nulinsrc.ok diff --git a/ChangeLog b/ChangeLog index d2153404..04dbb428 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-10-28 Arnold D. Robbins + + * awkgram.y (nextc): Don't allow '\0' even if check_for_bad + is false. Fixes a problem reported by Hanno Boeck . + 2015-10-16 Arnold D. Robbins * Makefile.am (SUBDIRS): Fix ordering so that diff --git a/awkgram.c b/awkgram.c index 845dbbef..8e408cac 100644 --- a/awkgram.c +++ b/awkgram.c @@ -5226,7 +5226,7 @@ again: 0 : work_ring_idx + 1; cur_char_ring[work_ring_idx] = 0; } - if (check_for_bad) + if (check_for_bad || *lexptr == '\0') check_bad_char(*lexptr); return (int) (unsigned char) *lexptr++; @@ -5235,7 +5235,7 @@ again: if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad) + if (check_for_bad || *lexptr == '\0') check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } diff --git a/awkgram.y b/awkgram.y index 11771609..2592d13a 100644 --- a/awkgram.y +++ b/awkgram.y @@ -2887,7 +2887,7 @@ again: 0 : work_ring_idx + 1; cur_char_ring[work_ring_idx] = 0; } - if (check_for_bad) + if (check_for_bad || *lexptr == '\0') check_bad_char(*lexptr); return (int) (unsigned char) *lexptr++; @@ -2896,7 +2896,7 @@ again: if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad) + if (check_for_bad || *lexptr == '\0') check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } diff --git a/test/ChangeLog b/test/ChangeLog index 6a888496..83174b03 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2015-10-28 Arnold D. Robbins + + * Makefile.am (nulinsrc): New test. + * nulinsrc.awk, nulinsrc.ok: New files. + 2015-10-26 Arnold D. Robbins * id.awk: Sort the output. Helps on z/OS. diff --git a/test/Makefile.am b/test/Makefile.am index 0d8658a0..97cf8d54 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -627,6 +627,8 @@ EXTRA_DIST = \ noparms.ok \ nors.in \ nors.ok \ + nulinsrc.awk \ + nulinsrc.ok \ nulrsend.awk \ nulrsend.in \ nulrsend.ok \ @@ -1040,7 +1042,7 @@ BASIC_TESTS = \ manglprm math membug1 messages minusstr mmap8k mtchi18n \ nasty nasty2 negexp negrange nested nfldstr nfloop nfneg nfset nlfldsep \ nlinstr nlstrina noeffect nofile nofmtch noloop1 noloop2 nonl \ - noparms nors nulrsend numindex numsubstr \ + noparms nors nulinsrc nulrsend numindex numsubstr \ octsub ofmt ofmta ofmtbig ofmtfidl ofmts ofs1 onlynl opasnidx opasnslf \ paramasfunc1 paramasfunc2 \ paramdup paramres paramtyp paramuninitglobal parse1 parsefld parseme \ diff --git a/test/Makefile.in b/test/Makefile.in index 7917fc2d..90b994c3 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -884,6 +884,8 @@ EXTRA_DIST = \ noparms.ok \ nors.in \ nors.ok \ + nulinsrc.awk \ + nulinsrc.ok \ nulrsend.awk \ nulrsend.in \ nulrsend.ok \ @@ -1296,7 +1298,7 @@ BASIC_TESTS = \ manglprm math membug1 messages minusstr mmap8k mtchi18n \ nasty nasty2 negexp negrange nested nfldstr nfloop nfneg nfset nlfldsep \ nlinstr nlstrina noeffect nofile nofmtch noloop1 noloop2 nonl \ - noparms nors nulrsend numindex numsubstr \ + noparms nors nulinsrc nulrsend numindex numsubstr \ octsub ofmt ofmta ofmtbig ofmtfidl ofmts ofs1 onlynl opasnidx opasnslf \ paramasfunc1 paramasfunc2 \ paramdup paramres paramtyp paramuninitglobal parse1 parsefld parseme \ @@ -3089,6 +3091,11 @@ noparms: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +nulinsrc: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + nulrsend: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 1723c33f..bb5712d5 100644 --- a/test/Maketests +++ b/test/Maketests @@ -550,6 +550,11 @@ noparms: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +nulinsrc: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + nulrsend: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/nulinsrc.awk b/test/nulinsrc.awk new file mode 100644 index 00000000..aecda862 Binary files /dev/null and b/test/nulinsrc.awk differ diff --git a/test/nulinsrc.ok b/test/nulinsrc.ok new file mode 100644 index 00000000..515f423c --- /dev/null +++ b/test/nulinsrc.ok @@ -0,0 +1,2 @@ +gawk: nulinsrc.awk:1: fatal: PEBKAC error: invalid character '\000' in source code +EXIT CODE: 2 -- cgit v1.2.3