b7b705
From 3bae605ce08375120f34761e5a4364253276ec88 Mon Sep 17 00:00:00 2001
b7b705
From: Daniel Stenberg <daniel@haxx.se>
b7b705
Date: Sat, 4 Nov 2017 16:42:21 +0100
b7b705
Subject: [PATCH 1/2] ntlm: avoid malloc(0) for zero length passwords
b7b705
b7b705
It triggers an assert() when built with memdebug since malloc(0) may
b7b705
return NULL *or* a valid pointer.
b7b705
b7b705
Detected by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4054
b7b705
b7b705
Assisted-by: Max Dymond
b7b705
Closes #2054
b7b705
b7b705
Upstream-commit: 685ef130575cdcf63fe9547757d88a49a40ef281
b7b705
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
b7b705
---
b7b705
 lib/curl_ntlm_core.c | 2 +-
b7b705
 1 file changed, 1 insertion(+), 1 deletion(-)
b7b705
b7b705
diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c
b7b705
index 8f3c00d..459f6f9 100644
b7b705
--- a/lib/curl_ntlm_core.c
b7b705
+++ b/lib/curl_ntlm_core.c
b7b705
@@ -385,7 +385,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(struct SessionHandle *data,
b7b705
                                    unsigned char *ntbuffer /* 21 bytes */)
b7b705
 {
b7b705
   size_t len = strlen(password);
b7b705
-  unsigned char *pw = malloc(len * 2);
b7b705
+  unsigned char *pw = len ? malloc(len * 2) : strdup("");
b7b705
   CURLcode result;
b7b705
   if(!pw)
b7b705
     return CURLE_OUT_OF_MEMORY;
b7b705
-- 
b7b705
2.17.1
b7b705
b7b705
b7b705
From 4c20ad72a35f44c31241a916ccf9a789a01d5ab8 Mon Sep 17 00:00:00 2001
b7b705
From: Daniel Stenberg <daniel@haxx.se>
b7b705
Date: Mon, 13 Aug 2018 10:35:52 +0200
b7b705
Subject: [PATCH 2/2] Curl_ntlm_core_mk_nt_hash: return error on too long
b7b705
 password
b7b705
b7b705
... since it would cause an integer overflow if longer than (max size_t
b7b705
/ 2).
b7b705
b7b705
This is CVE-2018-14618
b7b705
b7b705
Bug: https://curl.haxx.se/docs/CVE-2018-14618.html
b7b705
Closes #2756
b7b705
Reported-by: Zhaoyang Wu
b7b705
b7b705
Upstream-commit: 57d299a499155d4b327e341c6024e293b0418243
b7b705
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
b7b705
---
b7b705
 lib/curl_ntlm_core.c | 14 +++++++++++++-
b7b705
 1 file changed, 13 insertions(+), 1 deletion(-)
b7b705
b7b705
diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c
b7b705
index 459f6f9..1b6551f 100644
b7b705
--- a/lib/curl_ntlm_core.c
b7b705
+++ b/lib/curl_ntlm_core.c
b7b705
@@ -128,6 +128,15 @@ static void setup_des_key(const unsigned char *key_56,
b7b705
 
b7b705
 #else /* defined(USE_SSLEAY) */
b7b705
 
b7b705
+#ifndef SIZE_T_MAX
b7b705
+/* some limits.h headers have this defined, some don't */
b7b705
+#if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
b7b705
+#define SIZE_T_MAX 18446744073709551615U
b7b705
+#else
b7b705
+#define SIZE_T_MAX 4294967295U
b7b705
+#endif
b7b705
+#endif
b7b705
+
b7b705
 /*
b7b705
  * Turns a 56 bit key into the 64 bit, odd parity key.  Used by GnuTLS and NSS.
b7b705
  */
b7b705
@@ -385,8 +394,11 @@ CURLcode Curl_ntlm_core_mk_nt_hash(struct SessionHandle *data,
b7b705
                                    unsigned char *ntbuffer /* 21 bytes */)
b7b705
 {
b7b705
   size_t len = strlen(password);
b7b705
-  unsigned char *pw = len ? malloc(len * 2) : strdup("");
b7b705
+  unsigned char *pw;
b7b705
   CURLcode result;
b7b705
+  if(len > SIZE_T_MAX/2) /* avoid integer overflow */
b7b705
+    return CURLE_OUT_OF_MEMORY;
b7b705
+  pw = len ? malloc(len * 2) : strdup("");
b7b705
   if(!pw)
b7b705
     return CURLE_OUT_OF_MEMORY;
b7b705
 
b7b705
-- 
b7b705
2.17.1
b7b705