aboutsummaryrefslogtreecommitdiff
path: root/contrib/pgcrypto/crypt-des.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2015-10-05 10:06:29 -0400
committerNoah Misch <noah@leadboat.com>2015-10-05 10:06:35 -0400
commit48f6310bc5b0a2d883c9439fbc7eb1bd7bd4833d (patch)
treea87b67abce94b1411c947ddbc15a92ce91f71a51 /contrib/pgcrypto/crypt-des.c
parent7116a3e98a465a4dced4ecf0b330e0da4bd79873 (diff)
downloadpostgresql-48f6310bc5b0a2d883c9439fbc7eb1bd7bd4833d.tar.gz
postgresql-48f6310bc5b0a2d883c9439fbc7eb1bd7bd4833d.zip
pgcrypto: Detect and report too-short crypt() salts.
Certain short salts crashed the backend or disclosed a few bytes of backend memory. For existing salt-induced error conditions, emit a message saying as much. Back-patch to 9.0 (all supported versions). Josh Kupershmidt Security: CVE-2015-5288
Diffstat (limited to 'contrib/pgcrypto/crypt-des.c')
-rw-r--r--contrib/pgcrypto/crypt-des.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/contrib/pgcrypto/crypt-des.c b/contrib/pgcrypto/crypt-des.c
index 9c5e334ff56..6834c28cf2f 100644
--- a/contrib/pgcrypto/crypt-des.c
+++ b/contrib/pgcrypto/crypt-des.c
@@ -682,9 +682,19 @@ px_crypt_des(const char *key, const char *setting)
if (*setting == _PASSWORD_EFMT1)
{
/*
- * "new"-style: setting - underscore, 4 bytes of count, 4 bytes of
- * salt key - unlimited characters
+ * "new"-style: setting must be a 9-character (underscore, then 4
+ * bytes of count, then 4 bytes of salt) string. See CRYPT(3) under
+ * the "Extended crypt" heading for further details.
+ *
+ * Unlimited characters of the input key are used. This is known as
+ * the "Extended crypt" DES method.
+ *
*/
+ if (strlen(setting) < 9)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid salt")));
+
for (i = 1, count = 0L; i < 5; i++)
count |= ascii_to_bin(setting[i]) << (i - 1) * 6;
@@ -724,10 +734,16 @@ px_crypt_des(const char *key, const char *setting)
#endif /* !DISABLE_XDES */
{
/*
- * "old"-style: setting - 2 bytes of salt key - up to 8 characters
+ * "old"-style: setting - 2 bytes of salt key - only up to the first 8
+ * characters of the input key are used.
*/
count = 25;
+ if (strlen(setting) < 2)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid salt")));
+
salt = (ascii_to_bin(setting[1]) << 6)
| ascii_to_bin(setting[0]);