Avoid integer overflow and buffer overrun in hstore_to_json().
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 4 Nov 2014 21:54:59 +0000 (16:54 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 4 Nov 2014 21:54:59 +0000 (16:54 -0500)
commitf44290b7b3763f339ed66f883c0e85bb3c3c4e88
treeeadc33f15c3c31df1233eef10302d865f907494e
parentf88300168b1c5786c4b167de17e1a0bbb252337e
Avoid integer overflow and buffer overrun in hstore_to_json().

This back-patches commit 0c5783ff301ae3e470000c918bfc2395129de4c5 into the
9.3 branch.  At the time, Heikki just thought he was fixing an unlikely
integer-overflow scenario, but in point of fact the original coding was
hopelessly broken: it supposed that escape_json never enlarges the data
more than 2X, which is wrong on its face.  The revised code eliminates
making any a-priori assumptions about the output length.

Per report from Saul Costa.  The bogus code doesn't exist before 9.3,
so no other branches need fixing.
contrib/hstore/hstore_io.c