summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2020-10-16 15:59:13 +0000
committerTom Lane2020-10-16 15:59:13 +0000
commit02a75f8369b1b14b709349ee60b29f79b70320f6 (patch)
treec26f1d2778567c1aa0826b36f1614193cf95a6dd
parentbc49f8780b361591141e35c03ffb17d4035847cb (diff)
Add missing error check in pgcrypto/crypt-md5.c.
In theory, the second px_find_digest call in px_crypt_md5 could fail even though the first one succeeded, since resource allocation is required. Don't skip testing for a failure. (If one did happen, the likely result would be a crash rather than clean recovery from an OOM failure.) The code's been like this all along, so back-patch to all supported branches. Daniel Gustafsson Discussion: https://postgr.es/m/[email protected]
-rw-r--r--contrib/pgcrypto/crypt-md5.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/contrib/pgcrypto/crypt-md5.c b/contrib/pgcrypto/crypt-md5.c
index b6466d3e317..d38721a1010 100644
--- a/contrib/pgcrypto/crypt-md5.c
+++ b/contrib/pgcrypto/crypt-md5.c
@@ -65,11 +65,17 @@ px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen)
/* get the length of the true salt */
sl = ep - sp;
- /* */
+ /* we need two PX_MD objects */
err = px_find_digest("md5", &ctx);
if (err)
return NULL;
err = px_find_digest("md5", &ctx1);
+ if (err)
+ {
+ /* this path is possible under low-memory circumstances */
+ px_md_free(ctx);
+ return NULL;
+ }
/* The password first, since that is what is most unknown */
px_md_update(ctx, (const uint8 *) pw, strlen(pw));