Blame SOURCES/0010-curl-7.76.1-CVE-2022-22576.patch

e078bf
From 85d1103c2fc0c9b1bdfae470dbafd45758e1c2f0 Mon Sep 17 00:00:00 2001
e078bf
From: Patrick Monnerat <patrick@monnerat.net>
e078bf
Date: Mon, 25 Apr 2022 11:44:05 +0200
e078bf
Subject: [PATCH] url: check sasl additional parameters for connection reuse.
e078bf
e078bf
Also move static function safecmp() as non-static Curl_safecmp() since
e078bf
its purpose is needed at several places.
e078bf
e078bf
Bug: https://curl.se/docs/CVE-2022-22576.html
e078bf
e078bf
CVE-2022-22576
e078bf
e078bf
Closes #8746
e078bf
e078bf
Upstream-commit: 852aa5ad351ea53e5f01d2f44b5b4370c2bf5425
e078bf
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
e078bf
---
e078bf
 lib/strcase.c   | 10 ++++++++++
e078bf
 lib/strcase.h   |  2 ++
e078bf
 lib/url.c       | 13 ++++++++++++-
e078bf
 lib/urldata.h   |  1 +
e078bf
 lib/vtls/vtls.c | 21 ++++++---------------
e078bf
 5 files changed, 31 insertions(+), 16 deletions(-)
e078bf
e078bf
diff --git a/lib/strcase.c b/lib/strcase.c
e078bf
index dd46ca1..692a3f1 100644
e078bf
--- a/lib/strcase.c
e078bf
+++ b/lib/strcase.c
e078bf
@@ -251,6 +251,16 @@ void Curl_strntolower(char *dest, const char *src, size_t n)
e078bf
   } while(*src++ && --n);
e078bf
 }
e078bf
 
e078bf
+/* Compare case-sensitive NUL-terminated strings, taking care of possible
e078bf
+ * null pointers. Return true if arguments match.
e078bf
+ */
e078bf
+bool Curl_safecmp(char *a, char *b)
e078bf
+{
e078bf
+  if(a && b)
e078bf
+    return !strcmp(a, b);
e078bf
+  return !a && !b;
e078bf
+}
e078bf
+
e078bf
 /* --- public functions --- */
e078bf
 
e078bf
 int curl_strequal(const char *first, const char *second)
e078bf
diff --git a/lib/strcase.h b/lib/strcase.h
e078bf
index b628656..382b80a 100644
e078bf
--- a/lib/strcase.h
e078bf
+++ b/lib/strcase.h
e078bf
@@ -48,4 +48,6 @@ char Curl_raw_toupper(char in);
e078bf
 void Curl_strntoupper(char *dest, const char *src, size_t n);
e078bf
 void Curl_strntolower(char *dest, const char *src, size_t n);
e078bf
 
e078bf
+bool Curl_safecmp(char *a, char *b);
e078bf
+
e078bf
 #endif /* HEADER_CURL_STRCASE_H */
e078bf
diff --git a/lib/url.c b/lib/url.c
e078bf
index adef2cd..94e3406 100644
e078bf
--- a/lib/url.c
e078bf
+++ b/lib/url.c
e078bf
@@ -768,6 +768,7 @@ static void conn_free(struct connectdata *conn)
e078bf
   Curl_safefree(conn->passwd);
e078bf
   Curl_safefree(conn->sasl_authzid);
e078bf
   Curl_safefree(conn->options);
e078bf
+  Curl_safefree(conn->oauth_bearer);
e078bf
   Curl_dyn_free(&conn->trailer);
e078bf
   Curl_safefree(conn->host.rawalloc); /* host name buffer */
e078bf
   Curl_safefree(conn->conn_to_host.rawalloc); /* host name buffer */
e078bf
@@ -1310,7 +1311,9 @@ ConnectionExists(struct Curl_easy *data,
e078bf
         /* This protocol requires credentials per connection,
e078bf
            so verify that we're using the same name and password as well */
e078bf
         if(strcmp(needle->user, check->user) ||
e078bf
-           strcmp(needle->passwd, check->passwd)) {
e078bf
+           strcmp(needle->passwd, check->passwd) ||
e078bf
+           !Curl_safecmp(needle->sasl_authzid, check->sasl_authzid) ||
e078bf
+           !Curl_safecmp(needle->oauth_bearer, check->oauth_bearer)) {
e078bf
           /* one of them was different */
e078bf
           continue;
e078bf
         }
e078bf
@@ -3554,6 +3557,14 @@ static CURLcode create_conn(struct Curl_easy *data,
e078bf
     }
e078bf
   }
e078bf
 
e078bf
+  if(data->set.str[STRING_BEARER]) {
e078bf
+    conn->oauth_bearer = strdup(data->set.str[STRING_BEARER]);
e078bf
+    if(!conn->oauth_bearer) {
e078bf
+      result = CURLE_OUT_OF_MEMORY;
e078bf
+      goto out;
e078bf
+    }
e078bf
+  }
e078bf
+
e078bf
 #ifdef USE_UNIX_SOCKETS
e078bf
   if(data->set.str[STRING_UNIX_SOCKET_PATH]) {
e078bf
     conn->unix_domain_socket = strdup(data->set.str[STRING_UNIX_SOCKET_PATH]);
e078bf
diff --git a/lib/urldata.h b/lib/urldata.h
e078bf
index cc8a600..03da59a 100644
e078bf
--- a/lib/urldata.h
e078bf
+++ b/lib/urldata.h
e078bf
@@ -991,6 +991,7 @@ struct connectdata {
e078bf
   char *passwd;  /* password string, allocated */
e078bf
   char *options; /* options string, allocated */
e078bf
   char *sasl_authzid;     /* authorisation identity string, allocated */
e078bf
+  char *oauth_bearer; /* OAUTH2 bearer, allocated */
e078bf
   unsigned char httpversion; /* the HTTP version*10 reported by the server */
e078bf
   struct curltime now;     /* "current" time */
e078bf
   struct curltime created; /* creation time */
e078bf
diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c
e078bf
index 03b85ba..a40ac06 100644
e078bf
--- a/lib/vtls/vtls.c
e078bf
+++ b/lib/vtls/vtls.c
e078bf
@@ -125,15 +125,6 @@ static bool blobcmp(struct curl_blob *first, struct curl_blob *second)
e078bf
   return !memcmp(first->data, second->data, first->len); /* same data */
e078bf
 }
e078bf
 
e078bf
-static bool safecmp(char *a, char *b)
e078bf
-{
e078bf
-  if(a && b)
e078bf
-    return !strcmp(a, b);
e078bf
-  else if(!a && !b)
e078bf
-    return TRUE; /* match */
e078bf
-  return FALSE; /* no match */
e078bf
-}
e078bf
-
e078bf
 
e078bf
 bool
e078bf
 Curl_ssl_config_matches(struct ssl_primary_config *data,
e078bf
@@ -146,12 +137,12 @@ Curl_ssl_config_matches(struct ssl_primary_config *data,
e078bf
      (data->verifystatus == needle->verifystatus) &&
e078bf
      blobcmp(data->cert_blob, needle->cert_blob) &&
e078bf
      blobcmp(data->issuercert_blob, needle->issuercert_blob) &&
e078bf
-     safecmp(data->CApath, needle->CApath) &&
e078bf
-     safecmp(data->CAfile, needle->CAfile) &&
e078bf
-     safecmp(data->issuercert, needle->issuercert) &&
e078bf
-     safecmp(data->clientcert, needle->clientcert) &&
e078bf
-     safecmp(data->random_file, needle->random_file) &&
e078bf
-     safecmp(data->egdsocket, needle->egdsocket) &&
e078bf
+     Curl_safecmp(data->CApath, needle->CApath) &&
e078bf
+     Curl_safecmp(data->CAfile, needle->CAfile) &&
e078bf
+     Curl_safecmp(data->issuercert, needle->issuercert) &&
e078bf
+     Curl_safecmp(data->clientcert, needle->clientcert) &&
e078bf
+     Curl_safecmp(data->random_file, needle->random_file) &&
e078bf
+     Curl_safecmp(data->egdsocket, needle->egdsocket) &&
e078bf
      Curl_safe_strcasecompare(data->cipher_list, needle->cipher_list) &&
e078bf
      Curl_safe_strcasecompare(data->cipher_list13, needle->cipher_list13) &&
e078bf
      Curl_safe_strcasecompare(data->curves, needle->curves) &&
e078bf
-- 
e078bf
2.34.1
e078bf