]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
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)
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

src/common/scram-common.c

index 389453187c2284b4f2b1b89464c1265e51c9daca..38c97ef0b4c1e7876a944ceb4bb6aafadf97afdc 100644 (file)
@@ -74,7 +74,7 @@ scram_SaltedPassword(const char *password,
        memcpy(result, Ui_prev, key_length);
 
        /* Subsequent iterations */
-       for (i = 2; i <= iterations; i++)
+       for (i = 1; i < iterations; i++)
        {
 #ifndef FRONTEND
                /*