Blame SOURCES/0040-curl-7.61.1-CVE-2022-32208.patch

11c65b
From d36661703e16bd740a3a928041b1e697a6617b98 Mon Sep 17 00:00:00 2001
11c65b
From: Daniel Stenberg <daniel@haxx.se>
11c65b
Date: Thu, 9 Jun 2022 09:27:24 +0200
11c65b
Subject: [PATCH] krb5: return error properly on decode errors
11c65b
11c65b
Bug: https://curl.se/docs/CVE-2022-32208.html
11c65b
CVE-2022-32208
11c65b
Reported-by: Harry Sintonen
11c65b
Closes #9051
11c65b
11c65b
Upstream-commit: 6ecdf5136b52af747e7bda08db9a748256b1cd09
11c65b
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
11c65b
---
11c65b
 lib/krb5.c     |  5 +----
11c65b
 lib/security.c | 19 +++++++++++++++----
11c65b
 2 files changed, 16 insertions(+), 8 deletions(-)
11c65b
11c65b
diff --git a/lib/krb5.c b/lib/krb5.c
11c65b
index 787137c..6f9e1f7 100644
11c65b
--- a/lib/krb5.c
11c65b
+++ b/lib/krb5.c
11c65b
@@ -86,11 +86,8 @@ krb5_decode(void *app_data, void *buf, int len,
11c65b
   enc.value = buf;
11c65b
   enc.length = len;
11c65b
   maj = gss_unwrap(&min, *context, &enc, &dec, NULL, NULL);
11c65b
-  if(maj != GSS_S_COMPLETE) {
11c65b
-    if(len >= 4)
11c65b
-      strcpy(buf, "599 ");
11c65b
+  if(maj != GSS_S_COMPLETE)
11c65b
     return -1;
11c65b
-  }
11c65b
 
11c65b
   memcpy(buf, dec.value, dec.length);
11c65b
   len = curlx_uztosi(dec.length);
11c65b
diff --git a/lib/security.c b/lib/security.c
11c65b
index 52cce97..c95f290 100644
11c65b
--- a/lib/security.c
11c65b
+++ b/lib/security.c
11c65b
@@ -64,6 +64,10 @@
11c65b
 /* The last #include file should be: */
11c65b
 #include "memdebug.h"
11c65b
 
11c65b
+/* Max string input length is a precaution against abuse and to detect junk
11c65b
+   input easier and better. */
11c65b
+#define CURL_MAX_INPUT_LENGTH 8000000
11c65b
+
11c65b
 static const struct {
11c65b
   enum protection_level level;
11c65b
   const char *name;
11c65b
@@ -192,6 +196,7 @@ static CURLcode read_data(struct connectdata *conn,
11c65b
 {
11c65b
   int len;
11c65b
   CURLcode result;
11c65b
+  int nread;
11c65b
 
11c65b
   result = socket_read(fd, &len, sizeof(len));
11c65b
   if(result)
11c65b
@@ -200,7 +205,10 @@ static CURLcode read_data(struct connectdata *conn,
11c65b
   if(len) {
11c65b
     /* only realloc if there was a length */
11c65b
     len = ntohl(len);
11c65b
-    buf->data = Curl_saferealloc(buf->data, len);
11c65b
+    if(len > CURL_MAX_INPUT_LENGTH)
11c65b
+      len = 0;
11c65b
+    else
11c65b
+      buf->data = Curl_saferealloc(buf->data, len);
11c65b
   }
11c65b
   if(!len || !buf->data)
11c65b
     return CURLE_OUT_OF_MEMORY;
11c65b
@@ -208,8 +216,11 @@ static CURLcode read_data(struct connectdata *conn,
11c65b
   result = socket_read(fd, buf->data, len);
11c65b
   if(result)
11c65b
     return result;
11c65b
-  buf->size = conn->mech->decode(conn->app_data, buf->data, len,
11c65b
-                                 conn->data_prot, conn);
11c65b
+  nread = conn->mech->decode(conn->app_data, buf->data, len,
11c65b
+                             conn->data_prot, conn);
11c65b
+  if(nread < 0)
11c65b
+    return CURLE_RECV_ERROR;
11c65b
+  buf->size = (size_t)nread;
11c65b
   buf->index = 0;
11c65b
   return CURLE_OK;
11c65b
 }
11c65b
-- 
11c65b
2.35.3
11c65b