Commit 0186ded5 authored by Heikki Linnakangas's avatar Heikki Linnakangas

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.
parent a54d5875
...@@ -411,6 +411,8 @@ pg_be_scram_build_verifier(const char *password) ...@@ -411,6 +411,8 @@ pg_be_scram_build_verifier(const char *password)
ereport(LOG, ereport(LOG,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("could not generate random salt"))); errmsg("could not generate random salt")));
if (prep_password)
pfree(prep_password);
return NULL; return NULL;
} }
......
...@@ -638,7 +638,11 @@ pg_fe_scram_build_verifier(const char *password) ...@@ -638,7 +638,11 @@ pg_fe_scram_build_verifier(const char *password)
/* Generate a random salt */ /* Generate a random salt */
if (!pg_frontend_random(saltbuf, SCRAM_DEFAULT_SALT_LEN)) if (!pg_frontend_random(saltbuf, SCRAM_DEFAULT_SALT_LEN))
{
if (prep_password)
free(prep_password);
return NULL; return NULL;
}
result = scram_build_verifier(saltbuf, SCRAM_DEFAULT_SALT_LEN, result = scram_build_verifier(saltbuf, SCRAM_DEFAULT_SALT_LEN,
SCRAM_DEFAULT_ITERATIONS, password); SCRAM_DEFAULT_ITERATIONS, password);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment