Hi, I stumbled upon a problem with the scram_iterations GUC where setting scram_iterations to INT_MAX and then creating a user causes the command to hang indefinitely.
postgres=# SET scram_iterations=2147483647; SET postgres=# CREATE ROLE maxscram WITH PASSWORD 'forever'; <hangs> I looked into the relevant code and found the issue. Each SCRAM iteration after the first is done in a loop with the following condition: int i; ... for (i = 2; i <= iterations; i++) { ... } For iterations = INT_MAX, the loop will never terminate since the condition is <= and adding 1 to INT_MAX will lead to i wrapping around to INT_MIN. I've fixed this by modifying the loop condition to be i < iterations. I've attached a patch with the fix. I considered adding a test as well, but since generating a password with a high number of iterations is very time-consuming, I'm not sure if that would be practical. I also tried adding this to the current CommitFest, but my account hasn't passed the cooldown period yet. Thanks, Kevin
fix_max_scram_iterations.patch
Description: Binary data