Avoid integer overflow in hstore_to_json().
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 21 Feb 2014 13:43:31 +0000 (15:43 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 21 Feb 2014 13:47:22 +0000 (15:47 +0200)
commit0c5783ff301ae3e470000c918bfc2395129de4c5
tree2e15c47ea6712798ecf519785d58dd3fae8f5326
parent8c059dffd83384fa0c2fe6050429d601355bc3af
Avoid integer overflow in hstore_to_json().

The length of the output buffer was calculated based on the size of the
argument hstore. On a sizeof(int) == 4 platform and a huge argument, it
could overflow, causing a too small buffer to be allocated.

Refactor the function to use a StringInfo instead of pre-allocating the
buffer. Makes it shorter and more readable, too.
contrib/hstore/hstore_io.c