summaryrefslogtreecommitdiff
path: root/contrib/ltree/ltree_gist.c
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2023-04-23 13:58:25 +0300
committerAlexander Korotkov <akorotkov@postgresql.org>2023-04-23 14:00:16 +0300
commit48c6825d0ec8a5021e95aea666944e9345ceb77d (patch)
treea83660291627660d7172605b9aaa02a47529475d /contrib/ltree/ltree_gist.c
parent02191136cb25670dc9f086248f7b495d68c965d5 (diff)
Validate ltree siglen GiST option to be int-aligned
Unaligned siglen could lead to an unaligned access to subsequent key fields. Backpatch to 13, where opclass options were introduced. Reported-by: Alexander Lakhin Bug: 17847 Discussion: https://postgr.es/m/17847-171232970bea406b%40postgresql.org Reviewed-by: Tom Lane, Pavel Borisov, Alexander Lakhin Backpatch-through: 13
Diffstat (limited to 'contrib/ltree/ltree_gist.c')
-rw-r--r--contrib/ltree/ltree_gist.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c
index d384e1f5762..f5b4155594d 100644
--- a/contrib/ltree/ltree_gist.c
+++ b/contrib/ltree/ltree_gist.c
@@ -716,6 +716,18 @@ ltree_consistent(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(res);
}
+static void
+ltree_gist_relopts_validator(void *parsed_options, relopt_value *vals,
+ int nvals)
+{
+ LtreeGistOptions *options = (LtreeGistOptions *) parsed_options;
+
+ if (options->siglen != INTALIGN(options->siglen))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("siglen value must be a multiple of %d", ALIGNOF_INT)));
+}
+
Datum
ltree_gist_options(PG_FUNCTION_ARGS)
{
@@ -724,8 +736,11 @@ ltree_gist_options(PG_FUNCTION_ARGS)
init_local_reloptions(relopts, sizeof(LtreeGistOptions));
add_local_int_reloption(relopts, "siglen",
"signature length in bytes",
- LTREE_SIGLEN_DEFAULT, 1, LTREE_SIGLEN_MAX,
+ LTREE_SIGLEN_DEFAULT,
+ INTALIGN(1),
+ LTREE_SIGLEN_MAX,
offsetof(LtreeGistOptions, siglen));
+ register_reloptions_validator(relopts, ltree_gist_relopts_validator);
PG_RETURN_VOID();
}