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