diff options
author | Tom Lane | 2014-05-16 19:11:51 +0000 |
---|---|---|
committer | Tom Lane | 2014-05-16 19:11:51 +0000 |
commit | 82bbb60c30dbff0633da34387ccab58d843379b5 (patch) | |
tree | 3a3ea1b1da2dfe6f0a80c97cd6fd7f3d79e83717 /contrib/btree_gist/btree_interval.c | |
parent | d900e192a3ef2dd73fae4522c35aadce6d72a534 (diff) |
Fix valgrind warning for btree_gist indexes on macaddr.
The macaddr opclass stores two macaddr structs (each of size 6) in an
index column that's declared as being of type gbtreekey16, ie 16 bytes.
In the original coding this led to passing a palloc'd value of size 12
to the index insertion code, so that data would be fetched past the
end of the allocated value during index tuple construction. This makes
valgrind unhappy. In principle it could result in a SIGSEGV, though
with the current implementation of palloc there's no risk since
the 12-byte request size would be rounded up to 16 bytes anyway.
To fix, add a field to struct gbtree_ninfo showing the declared size of
the index datums, and use that in the palloc requests; and use palloc0
to be sure that any wasted bytes are cleanly initialized.
Per report from Andres Freund. No back-patch since there's no current
risk of a real problem.
Diffstat (limited to 'contrib/btree_gist/btree_interval.c')
-rw-r--r-- | contrib/btree_gist/btree_interval.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/contrib/btree_gist/btree_interval.c b/contrib/btree_gist/btree_interval.c index 93a341eb77e..68d80e8e0ae 100644 --- a/contrib/btree_gist/btree_interval.c +++ b/contrib/btree_gist/btree_interval.c @@ -87,7 +87,9 @@ gbt_intv_dist(const void *a, const void *b) /* * INTERVALSIZE should be the actual size-on-disk of an Interval, as shown * in pg_type. This might be less than sizeof(Interval) if the compiler - * insists on adding alignment padding at the end of the struct. + * insists on adding alignment padding at the end of the struct. (Note: + * this concern is obsolete with the current definition of Interval, but + * was real before a separate "day" field was added to it.) */ #define INTERVALSIZE 16 @@ -95,6 +97,7 @@ static const gbtree_ninfo tinfo = { gbt_t_intv, sizeof(Interval), + 32, /* sizeof(gbtreekey32) */ gbt_intvgt, gbt_intvge, gbt_intveq, |