Skip to content

Commit 41493ba

Browse files
committed
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.
1 parent ad365b2 commit 41493ba

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/backend/libpq/auth.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,12 @@ CheckMD5Auth(Port *port, char **logdetail)
715715
errmsg("MD5 authentication is not supported when \"db_user_namespace\" is enabled")));
716716

717717
/* include the salt to use for computing the response */
718-
pg_backend_random(md5Salt, 4);
718+
if (!pg_backend_random(md5Salt, 4))
719+
{
720+
ereport(LOG,
721+
(errmsg("could not acquire random number for MD5 salt.")));
722+
return STATUS_ERROR;
723+
}
719724

720725
sendAuthRequest(port, AUTH_REQ_MD5, md5Salt, 4);
721726

src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,6 +3901,7 @@ BackendStartup(Port *port)
39013901
*/
39023902
if (!RandomCancelKey(&MyCancelKey))
39033903
{
3904+
free(bn);
39043905
ereport(LOG,
39053906
(errcode(ERRCODE_OUT_OF_MEMORY),
39063907
errmsg("could not acquire random number")));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy