Protect against overflow of ltree.numlevel and lquery.numlevel.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 28 Mar 2020 21:09:51 +0000 (17:09 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 28 Mar 2020 21:09:51 +0000 (17:09 -0400)
commit39491aa0da48efabea5f16eb5104a0eb0ae0b251
treeaf57355edd6b51f2c75323ece7a601aaeebe843f
parent211d8f65392f7add35bcd02f49648e514d9558fc
Protect against overflow of ltree.numlevel and lquery.numlevel.

These uint16 fields could be overflowed by excessively long input,
producing strange results.  Complain for invalid input.

Likewise check for out-of-range values of the repeat counts in lquery.
(We don't try too hard on that one, notably not bothering to detect
if atoi's result has overflowed.)

Also detect length overflow in ltree_concat.

In passing, be more consistent about whether "syntax error" messages
include the type name.  Also, clarify the documentation about what
the size limit is.

This has been broken for a long time, so back-patch to all supported
branches.

Nikita Glukhov, reviewed by Benjie Gillam and Tomas Vondra

Discussion: https://postgr.es/m/CAP_rww=waX2Oo6q+MbMSiZ9ktdj6eaJj0cQzNu=Ry2cCDij5fw@mail.gmail.com
contrib/ltree/expected/ltree.out
contrib/ltree/ltree.h
contrib/ltree/ltree_io.c
contrib/ltree/ltree_op.c
contrib/ltree/sql/ltree.sql
doc/src/sgml/ltree.sgml