1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-12 21:01:52 +03:00

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: https://postgr.es/m/CAM45KeEMm8hnxdTOxA98qhfZ9CzGDdgy3mxgJmy0c+2WwjA6Zg@mail.gmail.com
This commit is contained in:
Richard Guo
2025-03-26 17:46:51 +09:00
parent f186f90e55
commit 34fbfe1f57

View File

@ -74,7 +74,7 @@ scram_SaltedPassword(const char *password,
memcpy(result, Ui_prev, key_length); memcpy(result, Ui_prev, key_length);
/* Subsequent iterations */ /* Subsequent iterations */
for (i = 2; i <= iterations; i++) for (i = 1; i < iterations; i++)
{ {
#ifndef FRONTEND #ifndef FRONTEND
/* /*