summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2015-11-23 09:58:55 +0000
committerotto <otto@openbsd.org>2015-11-23 09:58:55 +0000
commitf12ec01096538472cd742f1fa351a10748a47df4 (patch)
tree0471ac530ff39f2b003548f062b3a219d38cd31b
parentInsert new ports at the head of the list and stop assuming its (diff)
downloadwireguard-openbsd-f12ec01096538472cd742f1fa351a10748a47df4.tar.xz
wireguard-openbsd-f12ec01096538472cd742f1fa351a10748a47df4.zip
- fix printing of non-ascii chars in error message
- solve a couple of problems found by Michael McConville using afl: printing of null nodes, and generating cyclic "trees". These can only happen on invalid input, afaik. ok benno@
-rw-r--r--usr.bin/bc/bc.y25
1 files changed, 15 insertions, 10 deletions
diff --git a/usr.bin/bc/bc.y b/usr.bin/bc/bc.y
index 2a31a7eaefb..537e8bb832a 100644
--- a/usr.bin/bc/bc.y
+++ b/usr.bin/bc/bc.y
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: bc.y,v 1.48 2015/10/10 19:28:54 deraadt Exp $ */
+/* $OpenBSD: bc.y,v 1.49 2015/11/23 09:58:55 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -72,7 +72,7 @@ static void grow(void);
static ssize_t cs(const char *);
static ssize_t as(const char *);
static ssize_t node(ssize_t, ...);
-static void emit(ssize_t);
+static void emit(ssize_t, int);
static void emit_macro(int, ssize_t);
static void free_tree(void);
static ssize_t numnode(int);
@@ -175,7 +175,7 @@ program : /* empty */
input_item : semicolon_list NEWLINE
{
- emit($1);
+ emit($1, 0);
macro_char = reset_macro_char;
putchar('\n');
free_tree();
@@ -803,12 +803,17 @@ node(ssize_t arg, ...)
}
static void
-emit(ssize_t i)
+emit(ssize_t i, int level)
{
- if (instructions[i].index >= 0)
- while (instructions[i].index != END_NODE)
- emit(instructions[i++].index);
- else
+ if (level > 1000)
+ errx(1, "internal error: tree level > 1000");
+ if (instructions[i].index >= 0) {
+ while (instructions[i].index != END_NODE &&
+ instructions[i].index != i) {
+ emit(instructions[i].index, level + 1);
+ i++;
+ }
+ } else if (instructions[i].index != END_NODE)
fputs(instructions[i].u.cstr, stdout);
}
@@ -816,7 +821,7 @@ static void
emit_macro(int node, ssize_t code)
{
putchar('[');
- emit(code);
+ emit(code, 0);
printf("]s%s\n", instructions[node].u.cstr);
nesting--;
}
@@ -951,7 +956,7 @@ yyerror(char *s)
!isprint((unsigned char)yytext[0]))
n = asprintf(&str,
"%s: %s:%d: %s: ascii char 0x%02x unexpected",
- __progname, filename, lineno, s, yytext[0]);
+ __progname, filename, lineno, s, yytext[0] & 0xff);
else
n = asprintf(&str, "%s: %s:%d: %s: %s unexpected",
__progname, filename, lineno, s, yytext);