Fix tuple_data_split() to not open a relation without any lock.
authorTom Lane
Mon, 1 Oct 2018 15:51:07 +0000 (11:51 -0400)
committerTom Lane
Mon, 1 Oct 2018 15:51:07 +0000 (11:51 -0400)
commit370b28ccd430ed90125e8a2e016c617658f11b9f
tree14c440b2545f022978c1d08c0b8150fffd1865f2
parentdb01fc97ad80e6e29dd5a2d5736cfd3e484f9a30
Fix tuple_data_split() to not open a relation without any lock.

contrib/pageinspect's tuple_data_split() function thought it could get
away with opening the referenced relation with NoLock.  In practice
there's no guarantee that the current session holds any lock on that
rel (even if we just read a page from it), so that this is unsafe.

Switch to using AccessShareLock.  Also, postpone closing the relation,
so that we needn't copy its tupdesc.  Also, fix unsafe use of
att_isnull() for attributes past the end of the tuple.

Per testing with a patch that complains if we open a relation without
holding any lock on it.  I don't plan to back-patch that patch, but we
should close the holes it identifies in all supported branches.

Discussion: https://postgr.es/m/2038.1538335244@sss.pgh.pa.us
contrib/pageinspect/heapfuncs.c