From b78cb75ba7b716de2c166ca002da54f6db2b22d0 Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Mon, 7 Feb 2005 03:55:28 +0000 Subject: [PATCH] Prevent 4 more buffer overruns in the PL/PgSQL parser. This is just a minimally-invasive fix for stable branches; a cleaner fix will be committed to HEAD soon. --- src/pl/plpgsql/src/gram.y | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/pl/plpgsql/src/gram.y b/src/pl/plpgsql/src/gram.y index 66f6edf246..753b19ba48 100644 --- a/src/pl/plpgsql/src/gram.y +++ b/src/pl/plpgsql/src/gram.y @@ -1711,6 +1711,15 @@ read_sql_construct(int until, plpgsql_dstring_append(&ds, yytext); break; } + + /* Check for array overflow */ + if (nparams >= 1024) + { + plpgsql_error_lineno = lno; + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many variables specified in SQL statement"))); + } } expr = malloc(sizeof(PLpgSQL_expr) + sizeof(int) * nparams - sizeof(int)); @@ -1856,6 +1865,15 @@ make_select_stmt(void) while ((tok = yylex()) == ',') { + /* Check for array overflow */ + if (nfields >= 1024) + { + plpgsql_error_lineno = plpgsql_scanner_lineno(); + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many INTO variables specified"))); + } + tok = yylex(); switch(tok) { @@ -1918,6 +1936,15 @@ make_select_stmt(void) plpgsql_dstring_append(&ds, yytext); break; } + + /* Check for array overflow */ + if (nparams >= 1024) + { + plpgsql_error_lineno = plpgsql_scanner_lineno(); + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many variables specified in SQL statement"))); + } } expr = malloc(sizeof(PLpgSQL_expr) + sizeof(int) * nparams - sizeof(int)); @@ -1989,6 +2016,15 @@ make_fetch_stmt(void) while ((tok = yylex()) == ',') { + /* Check for array overflow */ + if (nfields >= 1024) + { + plpgsql_error_lineno = plpgsql_scanner_lineno(); + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many INTO variables specified"))); + } + tok = yylex(); switch(tok) { -- 2.39.5