diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | awkgram.c | 40 | ||||
-rw-r--r-- | awkgram.y | 40 | ||||
-rw-r--r-- | builtin.c | 2 | ||||
-rw-r--r-- | test/ChangeLog | 6 | ||||
-rw-r--r-- | test/Makefile.am | 10 | ||||
-rw-r--r-- | test/Makefile.in | 10 | ||||
-rw-r--r-- | test/printhuge.awk | 3 | ||||
-rw-r--r-- | test/printhuge.ok | 1 |
9 files changed, 107 insertions, 15 deletions
@@ -1,3 +1,13 @@ +2014-07-10 Arnold D. Robbins <arnold@skeeve.com> + + * awkgram.y (check_for_bad): New routine to do the fatal message, + with smarter checking. + (nextc): Call it as appropriate. + + * builtin.c (format_tree): Add check for bad returns from mbrlen + to avoid trying to malloc (size_t) -1 bytes. Thanks to + mail.green.fox@gmail.com for the bug report. + 2014-07-03 Arnold D. Robbins <arnold@skeeve.com> * awkgram.y (nextc): Add bool check_for_bad parameter to check @@ -5130,6 +5130,34 @@ tokexpand() return tok; } +/* check_bad_char --- fatal if c isn't allowed in gawk source code */ + +/* + * The error message was inspired by someone who decided to put + * a physical \0 byte into the source code to see what would + * happen and then filed a bug report about it. Sigh. + */ + +static void +check_bad_char(int c) +{ + /* allow escapes. needed for autoconf. bleah. */ + switch (c) { + case '\a': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + return; + default: + break; + } + + if (iscntrl(c) && ! isspace(c)) + fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c); +} + /* nextc --- get the next input character */ #if MBS_SUPPORT @@ -5186,8 +5214,8 @@ again: 0 : work_ring_idx + 1; cur_char_ring[work_ring_idx] = 0; } - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return (int) (unsigned char) *lexptr++; } else { @@ -5195,8 +5223,8 @@ again: if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } } while (get_src_buf()); @@ -5213,8 +5241,8 @@ nextc(bool check_for_bad) if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } } while (get_src_buf()); @@ -2791,6 +2791,34 @@ tokexpand() return tok; } +/* check_bad_char --- fatal if c isn't allowed in gawk source code */ + +/* + * The error message was inspired by someone who decided to put + * a physical \0 byte into the source code to see what would + * happen and then filed a bug report about it. Sigh. + */ + +static void +check_bad_char(int c) +{ + /* allow escapes. needed for autoconf. bleah. */ + switch (c) { + case '\a': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + return; + default: + break; + } + + if (iscntrl(c) && ! isspace(c)) + fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c); +} + /* nextc --- get the next input character */ #if MBS_SUPPORT @@ -2847,8 +2875,8 @@ again: 0 : work_ring_idx + 1; cur_char_ring[work_ring_idx] = 0; } - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return (int) (unsigned char) *lexptr++; } else { @@ -2856,8 +2884,8 @@ again: if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } } while (get_src_buf()); @@ -2874,8 +2902,8 @@ nextc(bool check_for_bad) if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } } while (get_src_buf()); @@ -1112,7 +1112,7 @@ out0: memset(& state, 0, sizeof(state)); count = mbrlen(cp, arg->stlen, & state); - if (count > 0) { + if (count != (size_t) -1 && count != (size_t) -2 && count > 0) { prec = count; /* may need to increase fw so that padding happens, see pr_tail code */ if (fw > 0) diff --git a/test/ChangeLog b/test/ChangeLog index cb330593..cc921277 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2014-07-10 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (printhuge): New test. + * printhuge.awk, printhuge.ok: New files. + Test from mail.green.fox@gmail.com. + 2014-06-24 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (profile1, profile4, profile5): Adjust for change to diff --git a/test/Makefile.am b/test/Makefile.am index 05c88501..d4ef501c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -682,6 +682,8 @@ EXTRA_DIST = \ printfbad3.awk \ printfbad3.ok \ printfloat.awk \ + printhuge.awk \ + printhuge.ok \ printlang.awk \ prmarscl.awk \ prmarscl.ok \ @@ -1008,7 +1010,7 @@ GAWK_EXT_TESTS = \ lint lintold lintwarn \ manyfiles match1 match2 match3 mbstr1 \ nastyparm next nondec nondec2 \ - patsplit posix printfbad1 printfbad2 printfbad3 procinfs \ + patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \ profile1 profile2 profile3 profile4 profile5 pty1 \ rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \ rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \ @@ -1948,6 +1950,12 @@ dbugeval:: @$(AWK) --debug -f /dev/null < "$(srcdir)"/$@.in > _$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +printhuge:: + @echo $@ + @[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=en_US.UTF-8; \ + AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + # Targets generated for other tests: include Maketests diff --git a/test/Makefile.in b/test/Makefile.in index 70e7981b..449ff46b 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -928,6 +928,8 @@ EXTRA_DIST = \ printfbad3.awk \ printfbad3.ok \ printfloat.awk \ + printhuge.awk \ + printhuge.ok \ printlang.awk \ prmarscl.awk \ prmarscl.ok \ @@ -1253,7 +1255,7 @@ GAWK_EXT_TESTS = \ lint lintold lintwarn \ manyfiles match1 match2 match3 mbstr1 \ nastyparm next nondec nondec2 \ - patsplit posix printfbad1 printfbad2 printfbad3 procinfs \ + patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \ profile1 profile2 profile3 profile4 profile5 pty1 \ rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \ rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \ @@ -2370,6 +2372,12 @@ dbugeval:: @echo $@ @$(AWK) --debug -f /dev/null < "$(srcdir)"/$@.in > _$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +printhuge:: + @echo $@ + @[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=en_US.UTF-8; \ + AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ Gt-dummy: # file Maketests, generated from Makefile.am by the Gentests program addcomma: diff --git a/test/printhuge.awk b/test/printhuge.awk new file mode 100644 index 00000000..4d4fb7d4 --- /dev/null +++ b/test/printhuge.awk @@ -0,0 +1,3 @@ +BEGIN { + printf("%c", sprintf("%c", (0xffffff00+255))) +} diff --git a/test/printhuge.ok b/test/printhuge.ok new file mode 100644 index 00000000..ce542efa --- /dev/null +++ b/test/printhuge.ok @@ -0,0 +1 @@ +ÿ
\ No newline at end of file |