Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 Jul 2016 04:58:06 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r303571 - head/usr.bin/indent
Message-ID:  <201607310458.u6V4w6og081986@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Sun Jul 31 04:58:06 2016
New Revision: 303571
URL: https://svnweb.freebsd.org/changeset/base/303571

Log:
  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)

Modified:
  head/usr.bin/indent/indent_globs.h
  head/usr.bin/indent/parse.c

Modified: head/usr.bin/indent/indent_globs.h
==============================================================================
--- head/usr.bin/indent/indent_globs.h	Sun Jul 31 04:14:20 2016	(r303570)
+++ head/usr.bin/indent/indent_globs.h	Sun Jul 31 04:58:06 2016	(r303571)
@@ -226,7 +226,7 @@ struct fstate
             bodyf;		/* major body font */
 
 
-#define STACKSIZE 150
+#define	STACKSIZE 256
 
 struct parser_state {
     int         last_token;

Modified: head/usr.bin/indent/parse.c
==============================================================================
--- head/usr.bin/indent/parse.c	Sun Jul 31 04:14:20 2016	(r303570)
+++ head/usr.bin/indent/parse.c	Sun Jul 31 04:58:06 2016	(r303571)
@@ -42,6 +42,7 @@ static char sccsid[] = "@(#)parse.c	8.1 
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <err.h>
 #include <stdio.h>
 #include "indent_globs.h"
 #include "indent_codes.h"
@@ -200,6 +201,9 @@ parse(int tk) /* tk: the code for the co
 
     }				/* end of switch */
 
+    if (ps.tos >= STACKSIZE)
+	errx(1, "Parser stack overflow");
+
     reduce();			/* see if any reduction can be done */
 
 #ifdef debug



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201607310458.u6V4w6og081986>