pgsql: Fix valgrind warning for btree_gist indexes on macaddr. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix valgrind warning for btree_gist indexes on macaddr.
Date
Msg-id E1WlNY0-0002i0-N1@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/82bbb60c30dbff0633da34387ccab58d843379b5

Modified Files
--------------
contrib/btree_gist/btree_cash.c      |    1 +
contrib/btree_gist/btree_date.c      |    1 +
contrib/btree_gist/btree_float4.c    |    1 +
contrib/btree_gist/btree_float8.c    |    1 +
contrib/btree_gist/btree_inet.c      |    1 +
contrib/btree_gist/btree_int2.c      |    1 +
contrib/btree_gist/btree_int4.c      |    1 +
contrib/btree_gist/btree_int8.c      |    1 +
contrib/btree_gist/btree_interval.c  |    5 ++++-
contrib/btree_gist/btree_macaddr.c   |    1 +
contrib/btree_gist/btree_oid.c       |    1 +
contrib/btree_gist/btree_time.c      |    1 +
contrib/btree_gist/btree_ts.c        |    1 +
contrib/btree_gist/btree_utils_num.c |    6 ++++--
contrib/btree_gist/btree_utils_num.h |    3 ++-
15 files changed, 22 insertions(+), 4 deletions(-)


pgsql-committers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: pgsql: Add test case for logical decoding of prepared transactions.
Next
From: Tom Lane
Date:
Subject: pgsql: Fix a second cause of undersized pallocs for btree_gist indexes