|
| 1 | +From f1c9ae1e195f93a5d46434b067d17a60867d0f6a Mon Sep 17 00:00:00 2001 |
| 2 | +From: Sharath Srikanth Chellappa <sharathsr@microsoft.com> |
| 3 | +Date: Wed, 13 Nov 2024 14:18:44 -0800 |
| 4 | +Subject: [PATCH] Patch for CVE-2023-27535 |
| 5 | + |
| 6 | +Upstream patch: https://github.com/curl/curl/commit/8f4608468b890dc |
| 7 | + |
| 8 | +--- |
| 9 | + Utilities/cmcurl/lib/ftp.c | 29 +++++++++++++++++++++++++++-- |
| 10 | + Utilities/cmcurl/lib/ftp.h | 5 +++++ |
| 11 | + Utilities/cmcurl/lib/setopt.c | 1 + |
| 12 | + Utilities/cmcurl/lib/strcase.c | 22 ++++++++++++++++++++++ |
| 13 | + Utilities/cmcurl/lib/strcase.h | 2 ++ |
| 14 | + Utilities/cmcurl/lib/url.c | 16 +++++++++++++++- |
| 15 | + Utilities/cmcurl/lib/urldata.h | 4 ++-- |
| 16 | + 7 files changed, 74 insertions(+), 5 deletions(-) |
| 17 | + |
| 18 | +diff --git a/Utilities/cmcurl/lib/ftp.c b/Utilities/cmcurl/lib/ftp.c |
| 19 | +index 425b0afec6..776a65f956 100644 |
| 20 | +--- a/Utilities/cmcurl/lib/ftp.c |
| 21 | ++++ b/Utilities/cmcurl/lib/ftp.c |
| 22 | +@@ -4084,6 +4084,8 @@ static CURLcode ftp_disconnect(struct Curl_easy *data, |
| 23 | + } |
| 24 | + |
| 25 | + freedirs(ftpc); |
| 26 | ++ Curl_safefree(ftpc->account); |
| 27 | ++ Curl_safefree(ftpc->alternative_to_user); |
| 28 | + Curl_safefree(ftpc->prevpath); |
| 29 | + Curl_safefree(ftpc->server_os); |
| 30 | + Curl_pp_disconnect(pp); |
| 31 | +@@ -4344,11 +4346,32 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data, |
| 32 | + { |
| 33 | + char *type; |
| 34 | + struct FTP *ftp; |
| 35 | ++ CURLcode result = CURLE_OK; |
| 36 | ++ struct ftp_conn *ftpc = &conn->proto.ftpc; |
| 37 | + |
| 38 | +- data->req.p.ftp = ftp = calloc(sizeof(struct FTP), 1); |
| 39 | ++ ftp = calloc(sizeof(struct FTP), 1); |
| 40 | + if(NULL == ftp) |
| 41 | + return CURLE_OUT_OF_MEMORY; |
| 42 | + |
| 43 | ++ /* clone connection related data that is FTP specific */ |
| 44 | ++ if(data->set.str[STRING_FTP_ACCOUNT]) { |
| 45 | ++ ftpc->account = strdup(data->set.str[STRING_FTP_ACCOUNT]); |
| 46 | ++ if(!ftpc->account) { |
| 47 | ++ free(ftp); |
| 48 | ++ return CURLE_OUT_OF_MEMORY; |
| 49 | ++ } |
| 50 | ++ } |
| 51 | ++ if(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]) { |
| 52 | ++ ftpc->alternative_to_user = |
| 53 | ++ strdup(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); |
| 54 | ++ if(!ftpc->alternative_to_user) { |
| 55 | ++ Curl_safefree(ftpc->account); |
| 56 | ++ free(ftp); |
| 57 | ++ return CURLE_OUT_OF_MEMORY; |
| 58 | ++ } |
| 59 | ++ } |
| 60 | ++ data->req.p.ftp = ftp; |
| 61 | ++ |
| 62 | + ftp->path = &data->state.up.path[1]; /* don't include the initial slash */ |
| 63 | + |
| 64 | + /* FTP URLs support an extension like ";type=<typecode>" that |
| 65 | +@@ -4383,7 +4406,9 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data, |
| 66 | + /* get some initial data into the ftp struct */ |
| 67 | + ftp->transfer = PPTRANSFER_BODY; |
| 68 | + ftp->downloadsize = 0; |
| 69 | +- conn->proto.ftpc.known_filesize = -1; /* unknown size for now */ |
| 70 | ++ ftpc->known_filesize = -1; /* unknown size for now */ |
| 71 | ++ ftpc->use_ssl = data->set.use_ssl; |
| 72 | ++ ftpc->ccc = data->set.ftp_ccc; |
| 73 | + |
| 74 | + return CURLE_OK; |
| 75 | + } |
| 76 | +diff --git a/Utilities/cmcurl/lib/ftp.h b/Utilities/cmcurl/lib/ftp.h |
| 77 | +index 1cfdac0851..afca25b469 100644 |
| 78 | +--- a/Utilities/cmcurl/lib/ftp.h |
| 79 | ++++ b/Utilities/cmcurl/lib/ftp.h |
| 80 | +@@ -115,6 +115,8 @@ struct FTP { |
| 81 | + struct */ |
| 82 | + struct ftp_conn { |
| 83 | + struct pingpong pp; |
| 84 | ++ char *account; |
| 85 | ++ char *alternative_to_user; |
| 86 | + char *entrypath; /* the PWD reply when we logged on */ |
| 87 | + char *file; /* url-decoded file name (or path) */ |
| 88 | + char **dirs; /* realloc()ed array for path components */ |
| 89 | +@@ -144,6 +146,9 @@ struct ftp_conn { |
| 90 | + ftpstate state; /* always use ftp.c:state() to change state! */ |
| 91 | + ftpstate state_saved; /* transfer type saved to be reloaded after |
| 92 | + data connection is established */ |
| 93 | ++ unsigned char use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or |
| 94 | ++ IMAP or POP3 or others! (type: curl_usessl)*/ |
| 95 | ++ unsigned char ccc; /* ccc level for this connection */ |
| 96 | + curl_off_t retr_size_saved; /* Size of retrieved file saved */ |
| 97 | + char *server_os; /* The target server operating system. */ |
| 98 | + curl_off_t known_filesize; /* file size is different from -1, if wildcard |
| 99 | +diff --git a/Utilities/cmcurl/lib/setopt.c b/Utilities/cmcurl/lib/setopt.c |
| 100 | +index fb8b86d474..10c6872bb3 100644 |
| 101 | +--- a/Utilities/cmcurl/lib/setopt.c |
| 102 | ++++ b/Utilities/cmcurl/lib/setopt.c |
| 103 | +@@ -2307,6 +2307,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) |
| 104 | + if((arg < CURLUSESSL_NONE) || (arg >= CURLUSESSL_LAST)) |
| 105 | + return CURLE_BAD_FUNCTION_ARGUMENT; |
| 106 | + data->set.use_ssl = (curl_usessl)arg; |
| 107 | ++ data->set.use_ssl = (unsigned char)arg; |
| 108 | + break; |
| 109 | + |
| 110 | + case CURLOPT_SSL_OPTIONS: |
| 111 | +diff --git a/Utilities/cmcurl/lib/strcase.c b/Utilities/cmcurl/lib/strcase.c |
| 112 | +index 955e3c79ea..29cc539cdf 100644 |
| 113 | +--- a/Utilities/cmcurl/lib/strcase.c |
| 114 | ++++ b/Utilities/cmcurl/lib/strcase.c |
| 115 | +@@ -251,6 +251,28 @@ void Curl_strntolower(char *dest, const char *src, size_t n) |
| 116 | + } while(*src++ && --n); |
| 117 | + } |
| 118 | + |
| 119 | ++/* |
| 120 | ++ * Curl_timestrcmp() returns 0 if the two strings are identical. The time this |
| 121 | ++ * function spends is a function of the shortest string, not of the contents. |
| 122 | ++ */ |
| 123 | ++int Curl_timestrcmp(const char *a, const char *b) |
| 124 | ++{ |
| 125 | ++ int match = 0; |
| 126 | ++ int i = 0; |
| 127 | ++ |
| 128 | ++ if(a && b) { |
| 129 | ++ while(1) { |
| 130 | ++ match |= a[i]^b[i]; |
| 131 | ++ if(!a[i] || !b[i]) |
| 132 | ++ break; |
| 133 | ++ i++; |
| 134 | ++ } |
| 135 | ++ } |
| 136 | ++ else |
| 137 | ++ return a || b; |
| 138 | ++ return match; |
| 139 | ++} |
| 140 | ++ |
| 141 | + /* --- public functions --- */ |
| 142 | + |
| 143 | + int curl_strequal(const char *first, const char *second) |
| 144 | +diff --git a/Utilities/cmcurl/lib/strcase.h b/Utilities/cmcurl/lib/strcase.h |
| 145 | +index 10dc698817..6fdb32ed08 100644 |
| 146 | +--- a/Utilities/cmcurl/lib/strcase.h |
| 147 | ++++ b/Utilities/cmcurl/lib/strcase.h |
| 148 | +@@ -48,4 +48,6 @@ char Curl_raw_toupper(char in); |
| 149 | + void Curl_strntoupper(char *dest, const char *src, size_t n); |
| 150 | + void Curl_strntolower(char *dest, const char *src, size_t n); |
| 151 | + |
| 152 | ++int Curl_timestrcmp(const char *first, const char *second); |
| 153 | ++ |
| 154 | + #endif /* HEADER_CURL_STRCASE_H */ |
| 155 | +diff --git a/Utilities/cmcurl/lib/url.c b/Utilities/cmcurl/lib/url.c |
| 156 | +index ca40322504..e00c56300b 100644 |
| 157 | +--- a/Utilities/cmcurl/lib/url.c |
| 158 | ++++ b/Utilities/cmcurl/lib/url.c |
| 159 | +@@ -1334,10 +1334,24 @@ ConnectionExists(struct Curl_easy *data, |
| 160 | + (data->state.httpwant < CURL_HTTP_VERSION_2_0)) |
| 161 | + continue; |
| 162 | + |
| 163 | +- if(get_protocol_family(needle->handler) & PROTO_FAMILY_SSH) { |
| 164 | ++#ifdef USE_SSH |
| 165 | ++ else if(get_protocol_family(needle->handler) & PROTO_FAMILY_SSH) { |
| 166 | + if(!ssh_config_matches(needle, check)) |
| 167 | + continue; |
| 168 | + } |
| 169 | ++#endif |
| 170 | ++#ifndef CURL_DISABLE_FTP |
| 171 | ++ else if(get_protocol_family(needle->handler) & PROTO_FAMILY_FTP) { |
| 172 | ++ /* Also match ACCOUNT, ALTERNATIVE-TO-USER, USE_SSL and CCC options */ |
| 173 | ++ if(Curl_timestrcmp(needle->proto.ftpc.account, |
| 174 | ++ check->proto.ftpc.account) || |
| 175 | ++ Curl_timestrcmp(needle->proto.ftpc.alternative_to_user, |
| 176 | ++ check->proto.ftpc.alternative_to_user) || |
| 177 | ++ (needle->proto.ftpc.use_ssl != check->proto.ftpc.use_ssl) || |
| 178 | ++ (needle->proto.ftpc.ccc != check->proto.ftpc.ccc)) |
| 179 | ++ continue; |
| 180 | ++ } |
| 181 | ++#endif |
| 182 | + |
| 183 | + if((needle->handler->flags&PROTOPT_SSL) |
| 184 | + #ifndef CURL_DISABLE_PROXY |
| 185 | +diff --git a/Utilities/cmcurl/lib/urldata.h b/Utilities/cmcurl/lib/urldata.h |
| 186 | +index 365b6821b1..ef3a58e55a 100644 |
| 187 | +--- a/Utilities/cmcurl/lib/urldata.h |
| 188 | ++++ b/Utilities/cmcurl/lib/urldata.h |
| 189 | +@@ -1729,8 +1729,6 @@ struct UserDefined { |
| 190 | + void *ssh_keyfunc_userp; /* custom pointer to callback */ |
| 191 | + enum CURL_NETRC_OPTION |
| 192 | + use_netrc; /* defined in include/curl.h */ |
| 193 | +- curl_usessl use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or |
| 194 | +- IMAP or POP3 or others! */ |
| 195 | + long new_file_perms; /* Permissions to use when creating remote files */ |
| 196 | + long new_directory_perms; /* Permissions to use when creating remote dirs */ |
| 197 | + long ssh_auth_types; /* allowed SSH auth types */ |
| 198 | +@@ -1773,6 +1771,8 @@ struct UserDefined { |
| 199 | + CURLU *uh; /* URL handle for the current parsed URL */ |
| 200 | + void *trailer_data; /* pointer to pass to trailer data callback */ |
| 201 | + curl_trailer_callback trailer_callback; /* trailing data callback */ |
| 202 | ++ unsigned char use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or |
| 203 | ++ IMAP or POP3 or others! (type: curl_usessl)*/ |
| 204 | + BIT(is_fread_set); /* has read callback been set to non-NULL? */ |
| 205 | + BIT(is_fwrite_set); /* has write callback been set to non-NULL? */ |
| 206 | + BIT(free_referer); /* set TRUE if 'referer' points to a string we |
| 207 | +-- |
| 208 | +2.45.2 |
0 commit comments