Commit 41493bac authored by Heikki Linnakangas's avatar Heikki Linnakangas

Fix two thinkos related to strong random keys.

pg_backend_random() is used for MD5 salt generation, but it can fail, and
no checks were done on its status code.

Fix memory leak, if generating a random number for a cancel key failed.

Both issues were spotted by Coverity. Fix by Michael Paquier.
parent ad365b2f
...@@ -715,7 +715,12 @@ CheckMD5Auth(Port *port, char **logdetail) ...@@ -715,7 +715,12 @@ CheckMD5Auth(Port *port, char **logdetail)
errmsg("MD5 authentication is not supported when \"db_user_namespace\" is enabled"))); errmsg("MD5 authentication is not supported when \"db_user_namespace\" is enabled")));
/* include the salt to use for computing the response */ /* include the salt to use for computing the response */
pg_backend_random(md5Salt, 4); if (!pg_backend_random(md5Salt, 4))
{
ereport(LOG,
(errmsg("could not acquire random number for MD5 salt.")));
return STATUS_ERROR;
}
sendAuthRequest(port, AUTH_REQ_MD5, md5Salt, 4); sendAuthRequest(port, AUTH_REQ_MD5, md5Salt, 4);
......
...@@ -3901,6 +3901,7 @@ BackendStartup(Port *port) ...@@ -3901,6 +3901,7 @@ BackendStartup(Port *port)
*/ */
if (!RandomCancelKey(&MyCancelKey)) if (!RandomCancelKey(&MyCancelKey))
{ {
free(bn);
ereport(LOG, ereport(LOG,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("could not acquire random number"))); errmsg("could not acquire random number")));
......
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