0001-Grow-isolation-spec-scanner-buffer-on-large-SQL-step.patch

application/octet-stream

Filename: 0001-Grow-isolation-spec-scanner-buffer-on-large-SQL-step.patch
Type: application/octet-stream
Part: 0
Message: Re: Two small patches for the isolationtester lexer

Patch

Format: format-patch
Series: patch 0001
Subject: Grow isolation spec scanner buffer on large SQL steps
File+
src/test/isolation/specscanner.l 17 4
From d862dd97e76b4cec256f90999b049edb6e5bc958 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Wed, 21 Feb 2018 20:42:24 +0100
Subject: [PATCH] Grow isolation spec scanner buffer on large SQL steps

The previous value of 1024 characters for the line buffer is quite
easy to bump into with large setup blocks. In case the SQL step is
larger than the current limit of 1024 chars, reallocate the buffer
until we hit an upper limit of LITBUF_MAX.
---
 src/test/isolation/specscanner.l | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/test/isolation/specscanner.l b/src/test/isolation/specscanner.l
index 481b32d1d7..6e8e4a6ff0 100644
--- a/src/test/isolation/specscanner.l
+++ b/src/test/isolation/specscanner.l
@@ -12,7 +12,11 @@
 
 static int	yyline = 1;			/* line number for error reporting */
 
-static char litbuf[1024];
+#define LITBUF_MAX	1024 * 1024 * 10
+#define LITBUF_INIT	1024
+
+static size_t litbufsize;
+static char *litbuf = NULL;
 static int litbufpos = 0;
 
 static void addlitchar(char c);
@@ -40,6 +44,10 @@ space			[ \t\r\f]
 comment			("#"{non_newline}*)
 
 %%
+%{
+	litbuf = pg_malloc(LITBUF_INIT);
+	litbufsize = LITBUF_INIT;
+%}
 
 permutation		{ return PERMUTATION; }
 session			{ return SESSION; }
@@ -100,10 +108,15 @@ teardown		{ return TEARDOWN; }
 static void
 addlitchar(char c)
 {
-	if (litbufpos >= sizeof(litbuf) - 1)
+	if (litbufpos >= litbufsize - 1)
 	{
-		fprintf(stderr, "SQL step too long\n");
-		exit(1);
+		litbufsize += litbufsize;
+		if (litbufsize > LITBUF_MAX)
+		{
+			fprintf(stderr, "SQL step too long\n");
+			exit(1);
+		}
+		litbuf = pg_realloc(litbuf, litbufsize);
 	}
 	litbuf[litbufpos++] = c;
 }
-- 
2.14.1.145.gb3622a4ee