From 9cdfe23ce31b1f3b63d9b6a50db5f0dc22c9b715 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 31 Jul 2016 04:58:06 +0000 Subject: [PATCH] indent(1): Bail out if there's no more space on the parser stack. Also increase the stack size still keeping a conservative value of 256. This is based on a similar changes done for PostgreSQL which instead uses a stack size of 1000. Differential Revision: https://reviews.freebsd.org/D6966 (Partial) Submitted by: Piotr Stefaniak (with changes) --- usr.bin/indent/indent_globs.h | 2 +- usr.bin/indent/parse.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h index 1e9970a8c95..6094d103525 100644 --- a/usr.bin/indent/indent_globs.h +++ b/usr.bin/indent/indent_globs.h @@ -226,7 +226,7 @@ struct fstate bodyf; /* major body font */ -#define STACKSIZE 150 +#define STACKSIZE 256 struct parser_state { int last_token; diff --git a/usr.bin/indent/parse.c b/usr.bin/indent/parse.c index 65d9a6bb8c4..4bc16c957bd 100644 --- a/usr.bin/indent/parse.c +++ b/usr.bin/indent/parse.c @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93"; #include __FBSDID("$FreeBSD$"); +#include #include #include "indent_globs.h" #include "indent_codes.h" @@ -200,6 +201,9 @@ parse(int tk) /* tk: the code for the construct scanned */ } /* end of switch */ + if (ps.tos >= STACKSIZE) + errx(1, "Parser stack overflow"); + reduce(); /* see if any reduction can be done */ #ifdef debug -- 2.11.4.GIT