git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d35cd06)
Limit max parameter number with MaxAllocSize
Tue, 2 Jul 2024 07:24:04 +0000 (09:24 +0200)
Tue, 2 Jul 2024 07:29:26 +0000 (09:29 +0200)
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


diff --git a/src/backend/parser/parse_param.c b/src/backend/parser/parse_param.c
index dbf1a7dff089b9f784355341767364e8988805ed..b617591ef682d75fe72851a87b88e3e6c3ca7cad 100644 (file)
--- a/src/backend/parser/parse_param.c
+++ b/src/backend/parser/parse_param.c
@@ -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),
diff --git a/src/test/regress/expected/prepare.out b/src/test/regress/expected/prepare.out
index 5815e17b39cc8c933b2c4ba9d00ecfbb96206bcd..853cbed248eca783a9778b4a3ae894e9e367b36a 100644 (file)
--- a/src/test/regress/expected/prepare.out
+++ b/src/test/regress/expected/prepare.out
@@ -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
diff --git a/src/test/regress/sql/prepare.sql b/src/test/regress/sql/prepare.sql
index c6098dc95ceee7cf2be3d8f18cd1bc7a519eec7f..1536f802d5eb9c30deb31ffd384a5fd3fb33a477 100644 (file)
--- a/src/test/regress/sql/prepare.sql
+++ b/src/test/regress/sql/prepare.sql
@@ -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
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /