Fix integer-overflow problem in scram_SaltedPassword()
authorRichard Guo <rguo@postgresql.org>
Wed, 26 Mar 2025 08:46:51 +0000 (17:46 +0900)
committerRichard Guo <rguo@postgresql.org>
Wed, 26 Mar 2025 08:51:44 +0000 (17:51 +0900)
commitde1484736dbef86a1b0b92544030ae655b1b2af3
treee6c56cfe72dfeea606bb414bc376220d7186edda
parent2f33de3cdbc814bcc4270aafd98880a12d265777
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 <kevinkbiju@gmail.com>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: http://postgr.es/m/CAM45KeEMm8hnxdTOxA98qhfZ9CzGDdgy3mxgJmy0c+2WwjA6Zg@mail.gmail.com
src/common/scram-common.c