pgsql: Guard against enormously long input in pg_saslprep(). - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Guard against enormously long input in pg_saslprep().
Date
Msg-id E1t5Udy-002snW-DZ@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Guard against enormously long input in pg_saslprep().

Coverity complained that pg_saslprep() could suffer integer overflow,
leading to under-allocation of the output buffer, if the input string
exceeds SIZE_MAX/4.  This hazard seems largely hypothetical, but it's
easy enough to defend against, so let's do so.

This patch creates a third place in src/common/ where we are locally
defining MaxAllocSize so that we can test against that in the same way
in backend and frontend compiles.  That seems like about two places
too many, so the next patch will move that into common/fe_memutils.h.
I'm hesitant to do that in back branches however.

Back-patch to v14.  The code looks similar in older branches, but
before commit 67a472d71 there was a separate test on the input string
length that prevented this hazard.

Per Coverity report.

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/dfff687f3c25fd114a7ab7d22df645716a98139f

Modified Files
--------------
src/common/saslprep.c | 7 +++++++
1 file changed, 7 insertions(+)


pgsql-committers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: pgsql: Implement pg_wal_replay_wait() stored procedure
Next
From: Nathan Bossart
Date:
Subject: pgsql: Ensure we have a snapshot when updating pg_index in index_drop()