Blame SOURCES/0022-curl-7.61.1-CVE-2020-8231.patch

9b977c
From 7a26092a9e21f1e0dc3cad69a580a7e2c7822ad0 Mon Sep 17 00:00:00 2001
9b977c
From: Daniel Stenberg <daniel@haxx.se>
9b977c
Date: Sun, 16 Aug 2020 11:34:35 +0200
9b977c
Subject: [PATCH] Curl_easy: remember last connection by id, not by pointer
9b977c
9b977c
CVE-2020-8231
9b977c
9b977c
Bug: https://curl.haxx.se/docs/CVE-2020-8231.html
9b977c
9b977c
Reported-by: Marc Aldorasi
9b977c
Closes #5824
9b977c
9b977c
Upstream-commit: 3c9e021f86872baae412a427e807fbfa2f3e8a22
9b977c
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9b977c
---
9b977c
 lib/connect.c | 19 ++++++++++---------
9b977c
 lib/easy.c    |  3 +--
9b977c
 lib/multi.c   |  5 +++--
9b977c
 lib/url.c     |  2 +-
9b977c
 lib/urldata.h |  2 +-
9b977c
 5 files changed, 16 insertions(+), 15 deletions(-)
9b977c
9b977c
diff --git a/lib/connect.c b/lib/connect.c
9b977c
index 41f2202..f724646 100644
9b977c
--- a/lib/connect.c
9b977c
+++ b/lib/connect.c
9b977c
@@ -1214,15 +1214,15 @@ CURLcode Curl_connecthost(struct connectdata *conn,  /* context */
9b977c
 }
9b977c
 
9b977c
 struct connfind {
9b977c
-  struct connectdata *tofind;
9b977c
-  bool found;
9b977c
+  long id_tofind;
9b977c
+  struct connectdata *found;
9b977c
 };
9b977c
 
9b977c
 static int conn_is_conn(struct connectdata *conn, void *param)
9b977c
 {
9b977c
   struct connfind *f = (struct connfind *)param;
9b977c
-  if(conn == f->tofind) {
9b977c
-    f->found = TRUE;
9b977c
+  if(conn->connection_id == f->id_tofind) {
9b977c
+    f->found = conn;
9b977c
     return 1;
9b977c
   }
9b977c
   return 0;
9b977c
@@ -1244,21 +1244,22 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
9b977c
    * - that is associated with a multi handle, and whose connection
9b977c
    *   was detached with CURLOPT_CONNECT_ONLY
9b977c
    */
9b977c
-  if(data->state.lastconnect && (data->multi_easy || data->multi)) {
9b977c
-    struct connectdata *c = data->state.lastconnect;
9b977c
+  if((data->state.lastconnect_id != -1) && (data->multi_easy || data->multi)) {
9b977c
+    struct connectdata *c;
9b977c
     struct connfind find;
9b977c
-    find.tofind = data->state.lastconnect;
9b977c
-    find.found = FALSE;
9b977c
+    find.id_tofind = data->state.lastconnect_id;
9b977c
+    find.found = NULL;
9b977c
 
9b977c
     Curl_conncache_foreach(data, data->multi_easy?
9b977c
                            &data->multi_easy->conn_cache:
9b977c
                            &data->multi->conn_cache, &find, conn_is_conn);
9b977c
 
9b977c
     if(!find.found) {
9b977c
-      data->state.lastconnect = NULL;
9b977c
+      data->state.lastconnect_id = -1;
9b977c
       return CURL_SOCKET_BAD;
9b977c
     }
9b977c
 
9b977c
+    c = find.found;
9b977c
     if(connp) {
9b977c
       /* only store this if the caller cares for it */
9b977c
       *connp = c;
9b977c
diff --git a/lib/easy.c b/lib/easy.c
9b977c
index 027d0be..fe61cdd 100644
9b977c
--- a/lib/easy.c
9b977c
+++ b/lib/easy.c
9b977c
@@ -919,8 +919,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
9b977c
 
9b977c
   /* the connection cache is setup on demand */
9b977c
   outcurl->state.conn_cache = NULL;
9b977c
-
9b977c
-  outcurl->state.lastconnect = NULL;
9b977c
+  outcurl->state.lastconnect_id = -1;
9b977c
 
9b977c
   outcurl->progress.flags    = data->progress.flags;
9b977c
   outcurl->progress.callback = data->progress.callback;
9b977c
diff --git a/lib/multi.c b/lib/multi.c
9b977c
index 0caf943..0f57fd5 100644
9b977c
--- a/lib/multi.c
9b977c
+++ b/lib/multi.c
9b977c
@@ -427,6 +427,7 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
9b977c
     data->state.conn_cache = &data->share->conn_cache;
9b977c
   else
9b977c
     data->state.conn_cache = &multi->conn_cache;
9b977c
+  data->state.lastconnect_id = -1;
9b977c
 
9b977c
 #ifdef USE_LIBPSL
9b977c
   /* Do the same for PSL. */
9b977c
@@ -644,11 +645,11 @@ static CURLcode multi_done(struct connectdata **connp,
9b977c
     /* the connection is no longer in use by this transfer */
9b977c
     if(Curl_conncache_return_conn(conn)) {
9b977c
       /* remember the most recently used connection */
9b977c
-      data->state.lastconnect = conn;
9b977c
+      data->state.lastconnect_id = conn->connection_id;
9b977c
       infof(data, "%s\n", buffer);
9b977c
     }
9b977c
     else
9b977c
-      data->state.lastconnect = NULL;
9b977c
+      data->state.lastconnect_id = -1;
9b977c
   }
9b977c
 
9b977c
   *connp = NULL; /* to make the caller of this function better detect that
9b977c
diff --git a/lib/url.c b/lib/url.c
9b977c
index dcc6cc8..d65d17d 100644
9b977c
--- a/lib/url.c
9b977c
+++ b/lib/url.c
9b977c
@@ -592,7 +592,7 @@ CURLcode Curl_open(struct Curl_easy **curl)
9b977c
       Curl_initinfo(data);
9b977c
 
9b977c
       /* most recent connection is not yet defined */
9b977c
-      data->state.lastconnect = NULL;
9b977c
+      data->state.lastconnect_id = -1;
9b977c
 
9b977c
       data->progress.flags |= PGRS_HIDE;
9b977c
       data->state.current_speed = -1; /* init to negative == impossible */
9b977c
diff --git a/lib/urldata.h b/lib/urldata.h
9b977c
index 67db3b2..4b70cc5 100644
9b977c
--- a/lib/urldata.h
9b977c
+++ b/lib/urldata.h
9b977c
@@ -1219,7 +1219,7 @@ struct UrlState {
9b977c
   /* buffers to store authentication data in, as parsed from input options */
9b977c
   struct curltime keeps_speed; /* for the progress meter really */
9b977c
 
9b977c
-  struct connectdata *lastconnect; /* The last connection, NULL if undefined */
9b977c
+  long lastconnect_id; /* The last connection, -1 if undefined */
9b977c
 
9b977c
   char *headerbuff; /* allocated buffer to store headers in */
9b977c
   size_t headersize;   /* size of the allocation */
9b977c
-- 
9b977c
2.25.4
9b977c