Subject: pgsql: Fix integer-overflow problem in scram_SaltedPassword()

From: Richard Guo <[email-masked]>
Date: Wed, 26 Mar 2025 08:50:31 +0000

Fix integer-overflow problem in scram_SaltedPassword()

Setting the iteration count for SCRAM secret generation to INT_MAX
will cause an infinite loop in scram_SaltedPassword() due to integer
overflow, as the loop uses the "i <= iterations" comparison.  To fix,
use "i < iterations" instead.

Back-patch to v16 where the user-settable GUC scram_iterations has
been added.

Author: Kevin K Biju <[email-masked]>
Reviewed-by: Richard Guo <[email-masked]>
Reviewed-by: Michael Paquier <[email-masked]>
Discussion: https://postgr.es/m/[email-masked]

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/34fbfe1f57d84163fea4e234bf78d3b5fd5364b1

Modified Files
--------------
src/common/scram-common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)