Reduce an unnecessary O(N^3) loop in lexer.
authorAndrew Gierth <rhodiumtoad@postgresql.org>
Thu, 23 Aug 2018 15:35:33 +0000 (16:35 +0100)
committerAndrew Gierth <rhodiumtoad@postgresql.org>
Thu, 23 Aug 2018 20:42:40 +0000 (21:42 +0100)
commitd4a63f829702cf28adb5db7e2ed44d2d9d893451
treee3e5164836e920f8fa0fa8768e84f98578fecfd7
parent5ca00774194dc179d02867d536b73eb85fffd227
Reduce an unnecessary O(N^3) loop in lexer.

The lexer's handling of operators contained an O(N^3) hazard when
dealing with long strings of + or - characters; it seems hard to
prevent this case from being O(N^2), but the additional N multiplier
was not needed.

Backpatch all the way since this has been there since 7.x, and it
presents at least a mild hazard in that trying to do Bind, PREPARE or
EXPLAIN on a hostile query could take excessive time (without
honouring cancels or timeouts) even if the query was never executed.
src/backend/parser/scan.l
src/fe_utils/psqlscan.l
src/interfaces/ecpg/preproc/pgc.l