Reduce an unnecessary O(N^3) loop in lexer.

Andrew Gierth <rhodiumtoad@postgresql.org>

Commit: 9923c934df437dd4a83b2b9921d314d8bfb292b3
Author: Andrew Gierth <rhodiumtoad@postgresql.org>
Date: 2018-08-23T20:29:15Z
Releases: 9.3.25
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.

Files

PathChange+/−
src/backend/parser/scan.l modified +21 −8
src/bin/psql/psqlscan.l modified +21 −8
src/interfaces/ecpg/preproc/pgc.l modified +21 −8