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
#include "parser/parse_param.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
+#include "utils/memutils.h"
typedef struct FixedParamState
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),
| 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
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