]> granicus.if.org Git - curl/commitdiff
ntlm: fix *_type3_message size check to avoid buffer overflow
authorDaniel Stenberg <daniel@haxx.se>
Thu, 3 Jan 2019 11:59:28 +0000 (12:59 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 4 Feb 2019 07:22:32 +0000 (08:22 +0100)
Bug: https://curl.haxx.se/docs/CVE-2019-3822.html
Reported-by: Wenxiang Qian
CVE-2019-3822

lib/vauth/ntlm.c

index 0ad4d972e35d64f81efebb739c5523f15f415e5e..6a8fc5ab3d0448be72210707db763c3e49fcd10a 100644 (file)
@@ -779,11 +779,14 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
   });
 
 #ifdef USE_NTRESPONSES
-  if(size < (NTLM_BUFSIZE - ntresplen)) {
-    DEBUGASSERT(size == (size_t)ntrespoff);
-    memcpy(&ntlmbuf[size], ptr_ntresp, ntresplen);
-    size += ntresplen;
+  /* ntresplen + size should not be risking an integer overflow here */
+  if(ntresplen + size > sizeof(ntlmbuf)) {
+    failf(data, "incoming NTLM message too big");
+    return CURLE_OUT_OF_MEMORY;
   }
+  DEBUGASSERT(size == (size_t)ntrespoff);
+  memcpy(&ntlmbuf[size], ptr_ntresp, ntresplen);
+  size += ntresplen;
 
   DEBUG_OUT({
     fprintf(stderr, "\n   ntresp=");