Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0186ded

Browse files
committed
Fix memory leaks if random salt generation fails.
In the backend, this is just to silence coverity warnings, but in the frontend, it's a genuine leak, even if extremely rare. Spotted by Coverity, patch by Michael Paquier.
1 parent a54d587 commit 0186ded

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/backend/libpq/auth-scram.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ pg_be_scram_build_verifier(const char *password)
411411
ereport(LOG,
412412
(errcode(ERRCODE_INTERNAL_ERROR),
413413
errmsg("could not generate random salt")));
414+
if (prep_password)
415+
pfree(prep_password);
414416
return NULL;
415417
}
416418

src/interfaces/libpq/fe-auth-scram.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,11 @@ pg_fe_scram_build_verifier(const char *password)
638638

639639
/* Generate a random salt */
640640
if (!pg_frontend_random(saltbuf, SCRAM_DEFAULT_SALT_LEN))
641+
{
642+
if (prep_password)
643+
free(prep_password);
641644
return NULL;
645+
}
642646

643647
result = scram_build_verifier(saltbuf, SCRAM_DEFAULT_SALT_LEN,
644648
SCRAM_DEFAULT_ITERATIONS, password);

0 commit comments

Comments
 (0)