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

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