]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Guard against enormously long input in pg_saslprep().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 28 Oct 2024 18:33:55 +0000 (14:33 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 28 Oct 2024 18:33:55 +0000 (14:33 -0400)
commitd130a64ee003bd6f272ad63f2721e204b443a582
treebad1cd93cf732fc9318d8735fa99a96cc8bbe5ab
parent55327256a049e3926d4d1cda39a7bb5886cbe03c
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.
src/common/saslprep.c