]> granicus.if.org Git - postgresql/commit
Set snprintf.c's maximum number of NL arguments to be 31.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Oct 2018 16:41:28 +0000 (12:41 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Oct 2018 16:41:28 +0000 (12:41 -0400)
commit6483381a4d0b7aab74e71579d92daf490cc54fb2
tree12cb1bf74c3f92fd40781341f7905a62a7984d70
parent7eed72333731fabd0fc816c0dfbadebe6d7d3063
Set snprintf.c's maximum number of NL arguments to be 31.

Previously, we used the platform's NL_ARGMAX if any, otherwise 16.
The trouble with this is that the platform value is hugely variable,
ranging from the POSIX-minimum 9 to as much as 64K on recent FreeBSD.
Values of more than a dozen or two have no practical use and slow down
the initialization of the argtypes array.  Worse, they cause snprintf.c
to consume far more stack space than was the design intention, possibly
resulting in stack-overflow crashes.

Standardize on 31, which is comfortably more than we need (it looks like
no existing translatable message has more than about 10 parameters).
I chose that, not 32, to make the array sizes powers of 2, for some
possible small gain in speed of the memset.

The lack of reported crashes suggests that the set of platforms we
use snprintf.c on (in released branches) may have no overlap with
the set where NL_ARGMAX has unreasonably large values.  But that's
not entirely clear, so back-patch to all supported branches.

Per report from Mateusz Guzik (via Thomas Munro).

Discussion: https://postgr.es/m/CAEepm=3VF=PUp2f8gU8fgZB22yPE_KBS0+e1AHAtQ=09schTHg@mail.gmail.com
src/port/snprintf.c