diff options
author | Noah Misch <noah@leadboat.com> | 2019-06-30 17:34:17 -0700 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2019-06-30 17:34:20 -0700 |
commit | 4b85f20f948d885875a1e1b89979e627b86e6e64 (patch) | |
tree | 218eca7bdfa2a0588848528ddb468438fef7f581 /src/include/utils/array.h | |
parent | 05dc5f4767e1c5ed157b2870f05d57f3378302f4 (diff) | |
download | postgresql-4b85f20f948d885875a1e1b89979e627b86e6e64.tar.gz postgresql-4b85f20f948d885875a1e1b89979e627b86e6e64.zip |
Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType.
UBSan complains about this. Instead, cast to a suitable type requiring
only 4-byte alignment. DatumGetAnyArrayP() already assumes one can cast
between AnyArrayType and ArrayType, so this doesn't introduce a new
assumption. Back-patch to 9.5, where AnyArrayType was introduced.
Reviewed by Tom Lane.
Discussion: https://postgr.es/m/20190629210334.GA1244217@rfd.leadboat.com
Diffstat (limited to 'src/include/utils/array.h')
-rw-r--r-- | src/include/utils/array.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/include/utils/array.h b/src/include/utils/array.h index afbb532e9c2..03d0db5a865 100644 --- a/src/include/utils/array.h +++ b/src/include/utils/array.h @@ -157,7 +157,10 @@ typedef struct ExpandedArrayHeader /* * Functions that can handle either a "flat" varlena array or an expanded - * array use this union to work with their input. + * array use this union to work with their input. Don't refer to "flt"; + * instead, cast to ArrayType. This struct nominally requires 8-byte + * alignment on 64-bit, but it's often used for an ArrayType having 4-byte + * alignment. UBSan complains about referencing "flt" in such cases. */ typedef union AnyArrayType { @@ -311,17 +314,21 @@ typedef struct ArrayIteratorData *ArrayIterator; * Macros for working with AnyArrayType inputs. Beware multiple references! */ #define AARR_NDIM(a) \ - (VARATT_IS_EXPANDED_HEADER(a) ? (a)->xpn.ndims : ARR_NDIM(&(a)->flt)) + (VARATT_IS_EXPANDED_HEADER(a) ? \ + (a)->xpn.ndims : ARR_NDIM((ArrayType *) (a))) #define AARR_HASNULL(a) \ (VARATT_IS_EXPANDED_HEADER(a) ? \ ((a)->xpn.dvalues != NULL ? (a)->xpn.dnulls != NULL : ARR_HASNULL((a)->xpn.fvalue)) : \ - ARR_HASNULL(&(a)->flt)) + ARR_HASNULL((ArrayType *) (a))) #define AARR_ELEMTYPE(a) \ - (VARATT_IS_EXPANDED_HEADER(a) ? (a)->xpn.element_type : ARR_ELEMTYPE(&(a)->flt)) + (VARATT_IS_EXPANDED_HEADER(a) ? \ + (a)->xpn.element_type : ARR_ELEMTYPE((ArrayType *) (a))) #define AARR_DIMS(a) \ - (VARATT_IS_EXPANDED_HEADER(a) ? (a)->xpn.dims : ARR_DIMS(&(a)->flt)) + (VARATT_IS_EXPANDED_HEADER(a) ? \ + (a)->xpn.dims : ARR_DIMS((ArrayType *) (a))) #define AARR_LBOUND(a) \ - (VARATT_IS_EXPANDED_HEADER(a) ? (a)->xpn.lbound : ARR_LBOUND(&(a)->flt)) + (VARATT_IS_EXPANDED_HEADER(a) ? \ + (a)->xpn.lbound : ARR_LBOUND((ArrayType *) (a))) /* |