Limit max parameter number with MaxAllocSize

MaxAllocSize puts an upper bound on the largest possible parameter
number ($268435455).  Use that limit instead of INT_MAX to report that
no parameters exist beyond that point instead of reporting an error
about the maximum allocation size being exceeded.

Author: Erik Wienhold <ewie@ewie.name>
Discussion: https://www.postgresql.org/message-id/flat/5d216d1c-91f6-4cbe-95e2-b4cbd930520c@ewie.name
This commit is contained in:
Peter Eisentraut 2024-07-02 09:24:04 +02:00
parent d35cd06199
commit 9c2e660b07
3 changed files with 10 additions and 1 deletions

View File

@ -31,6 +31,7 @@
#include "parser/parse_param.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
typedef struct FixedParamState
@ -136,7 +137,7 @@ variable_paramref_hook(ParseState *pstate, ParamRef *pref)
Param *param;
/* Check parameter number is in range */
if (paramno <= 0 || paramno > INT_MAX / sizeof(Oid))
if (paramno <= 0 || paramno > MaxAllocSize / sizeof(Oid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_PARAMETER),
errmsg("there is no parameter $%d", paramno),

View File

@ -184,6 +184,11 @@ SELECT name, statement, parameter_types, result_types FROM pg_prepared_statement
| UPDATE tenk1 SET stringu1 = $2 WHERE unique1 = $1; | |
(6 rows)
-- max parameter number and one above
PREPARE q9 AS SELECT $268435455, $268435456;
ERROR: there is no parameter $268435456
LINE 1: PREPARE q9 AS SELECT $268435455, $268435456;
^
-- test DEALLOCATE ALL;
DEALLOCATE ALL;
SELECT name, statement, parameter_types FROM pg_prepared_statements

View File

@ -78,6 +78,9 @@ PREPARE q8 AS
SELECT name, statement, parameter_types, result_types FROM pg_prepared_statements
ORDER BY name;
-- max parameter number and one above
PREPARE q9 AS SELECT $268435455, $268435456;
-- test DEALLOCATE ALL;
DEALLOCATE ALL;
SELECT name, statement, parameter_types FROM pg_prepared_statements