]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ntlm: avoid malloc(0) on zero length user and domain
authorDaniel Stenberg <daniel@haxx.se>
Sat, 28 Nov 2020 21:29:59 +0000 (22:29 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 29 Nov 2020 10:24:54 +0000 (11:24 +0100)
... and simplify the too-long checks somewhat.

Detected by OSS-Fuzz

Closes #6264

lib/curl_ntlm_core.c

index 9245c1d10a9a97fc547e776763cd93b430d32c00..9a075ac90fab91cb7aeea4078ccd7397d51cc81c 100644 (file)
@@ -580,15 +580,11 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen,
   unsigned char *identity;
   CURLcode result = CURLE_OK;
 
-  /* we do the length checks below separately to avoid integer overflow risk
-     on extreme data lengths */
-  if((userlen > SIZE_T_MAX/2) ||
-     (domlen > SIZE_T_MAX/2) ||
-     ((userlen + domlen) > SIZE_T_MAX/2))
+  if((userlen > CURL_MAX_INPUT_LENGTH) || (domlen > CURL_MAX_INPUT_LENGTH))
     return CURLE_OUT_OF_MEMORY;
 
   identity_len = (userlen + domlen) * 2;
-  identity = malloc(identity_len);
+  identity = malloc(identity_len + 1);
 
   if(!identity)
     return CURLE_OUT_OF_MEMORY;