未验证 提交 a3fba709 编写于 作者: O openharmony_ci 提交者: Gitee

!90 【LTS3.0】打补丁解决curl组件存在CVE漏洞(CVE-2022-32221、CVE-2022-42915、CVE-2022-42916)

Merge pull request !90 from wanghao-free/OpenHarmony-3.0-LTS
......@@ -209,7 +209,6 @@ static void connect_done(struct Curl_easy *data)
/* retore the protocol pointer */
data->req.p.http = s->prot_save;
s->prot_save = NULL;
infof(data, "CONNECT phase completed!");
}
}
......
......@@ -630,6 +630,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
}
else
data->set.method = HTTPREQ_GET;
data->set.upload = FALSE;
break;
case CURLOPT_HTTPPOST:
......
......@@ -735,15 +735,6 @@ static void conn_shutdown(struct Curl_easy *data, struct connectdata *conn)
DEBUGASSERT(data);
infof(data, "Closing connection %ld", conn->connection_id);
#ifndef USE_HYPER
if(conn->connect_state && conn->connect_state->prot_save) {
/* If this was closed with a CONNECT in progress, cleanup this temporary
struct arrangement */
data->req.p.http = NULL;
Curl_safefree(conn->connect_state->prot_save);
}
#endif
/* possible left-overs from the async name resolvers */
Curl_resolver_cancel(data);
......@@ -1994,9 +1985,56 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
return CURLE_OUT_OF_MEMORY;
}
hostname = data->state.up.hostname;
if(hostname && hostname[0] == '[') {
/* This looks like an IPv6 address literal. See if there is an address
scope. */
size_t hlen;
conn->bits.ipv6_ip = TRUE;
/* cut off the brackets! */
hostname++;
hlen = strlen(hostname);
hostname[hlen - 1] = 0;
zonefrom_url(uh, data, conn);
}
/* make sure the connect struct gets its own copy of the host name */
conn->host.rawalloc = strdup(hostname ? hostname : "");
if(!conn->host.rawalloc)
return CURLE_OUT_OF_MEMORY;
conn->host.name = conn->host.rawalloc;
/*************************************************************
* IDN-convert the hostnames
*************************************************************/
result = Curl_idnconvert_hostname(data, &conn->host);
if(result)
return result;
if(conn->bits.conn_to_host) {
result = Curl_idnconvert_hostname(data, &conn->conn_to_host);
if(result)
return result;
}
#ifndef CURL_DISABLE_PROXY
if(conn->bits.httpproxy) {
result = Curl_idnconvert_hostname(data, &conn->http_proxy.host);
if(result)
return result;
}
if(conn->bits.socksproxy) {
result = Curl_idnconvert_hostname(data, &conn->socks_proxy.host);
if(result)
return result;
}
#endif
#ifndef CURL_DISABLE_HSTS
/* HSTS upgrade */
if(data->hsts && strcasecompare("http", data->state.up.scheme)) {
if(Curl_hsts(data->hsts, data->state.up.hostname, TRUE)) {
/* This MUST use the IDN decoded name */
if(Curl_hsts(data->hsts, conn->host.name, TRUE)) {
char *url;
Curl_safefree(data->state.up.scheme);
uc = curl_url_set(uh, CURLUPART_SCHEME, "https", 0);
......@@ -2099,26 +2137,6 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
(void)curl_url_get(uh, CURLUPART_QUERY, &data->state.up.query, 0);
hostname = data->state.up.hostname;
if(hostname && hostname[0] == '[') {
/* This looks like an IPv6 address literal. See if there is an address
scope. */
size_t hlen;
conn->bits.ipv6_ip = TRUE;
/* cut off the brackets! */
hostname++;
hlen = strlen(hostname);
hostname[hlen - 1] = 0;
zonefrom_url(uh, data, conn);
}
/* make sure the connect struct gets its own copy of the host name */
conn->host.rawalloc = strdup(hostname ? hostname : "");
if(!conn->host.rawalloc)
return CURLE_OUT_OF_MEMORY;
conn->host.name = conn->host.rawalloc;
if(data->set.scope_id)
/* Override any scope that was set above. */
conn->scope_id = data->set.scope_id;
......@@ -3671,29 +3689,6 @@ static CURLcode create_conn(struct Curl_easy *data,
if(result)
goto out;
/*************************************************************
* IDN-convert the hostnames
*************************************************************/
result = Curl_idnconvert_hostname(data, &conn->host);
if(result)
goto out;
if(conn->bits.conn_to_host) {
result = Curl_idnconvert_hostname(data, &conn->conn_to_host);
if(result)
goto out;
}
#ifndef CURL_DISABLE_PROXY
if(conn->bits.httpproxy) {
result = Curl_idnconvert_hostname(data, &conn->http_proxy.host);
if(result)
goto out;
}
if(conn->bits.socksproxy) {
result = Curl_idnconvert_hostname(data, &conn->socks_proxy.host);
if(result)
goto out;
}
#endif
/*************************************************************
* Check whether the host and the "connect to host" are equal.
......
......@@ -69,7 +69,7 @@ test409 test410 \
\
test430 test431 test432 test433 test434 \
\
test442 test443 test444 \
test442 test443 test444 test445 \
\
test490 test491 test492 test493 test494 \
\
......@@ -217,7 +217,7 @@ test1800 test1801 \
test1908 test1909 test1910 test1911 test1912 test1913 test1914 test1915 \
test1916 test1917 test1918 \
\
test1933 test1934 test1935 test1936 \
test1933 test1934 test1935 test1936 test1948 \
\
test2000 test2001 test2002 test2003 test2004 \
\
......
<testcase>
<info>
<keywords>
HTTP
HTTP POST
HTTP PUT
</keywords>
</info>
# Server-side
<reply>
<data>
HTTP/1.1 200 OK
Date: Thu, 01 Nov 2001 14:49:00 GMT
Content-Type: text/html
Content-Length: 6
hello
</data>
<datacheck>
HTTP/1.1 200 OK
Date: Thu, 01 Nov 2001 14:49:00 GMT
Content-Type: text/html
Content-Length: 6
hello
HTTP/1.1 200 OK
Date: Thu, 01 Nov 2001 14:49:00 GMT
Content-Type: text/html
Content-Length: 6
hello
</datacheck>
</reply>
# Client-side
<client>
<server>
http
</server>
<name>
CURLOPT_POST after CURLOPT_UPLOAD reusing handle
</name>
<tool>
lib%TESTNUMBER
</tool>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<protocol>
PUT /%TESTNUMBER HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
Content-Length: 22
Expect: 100-continue
This is test PUT data
POST /1948 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
Content-Length: 22
Content-Type: application/x-www-form-urlencoded
This is test PUT data
</protocol>
</verify>
</testcase>
<testcase>
<info>
<keywords>
HTTP
HTTP proxy
</keywords>
</info>
#
# Server-side
<reply>
<connect>
HTTP/1.1 503 no just no
Date: Tue, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
Accept-Ranges: bytes
Content-Length: 6
Connection: close
-foo-
</connect>
</reply>
#
# Client-side
<client>
<features>
gopher
dict
http
ftp
imap
ldap
mqtt
pop3
rtsp
scp
sftp
smb
smtp
</features>
<server>
http-proxy
</server>
<name>
Refuse tunneling protocols through HTTP proxy
</name>
<command>
-x http://%HOSTIP:%PROXYPORT/%TESTNUMBER -p gopher://127.0.0.1 dict://127.0.0.1 http://moo https://example telnet://another ftp://yes ftps://again imap://more ldap://perhaps mqtt://yes pop3://mail rtsp://harder scp://copy sftp://files smb://wird smtp://send
</command>
</client>
#
# Verify data after the test has been "shot"
<verify>
# refused in the CONNECT
<errorcode>
56
</errorcode>
</verify>
</testcase>
......@@ -61,6 +61,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
lib1591 lib1592 lib1593 lib1594 lib1596 \
lib1905 lib1906 lib1907 lib1908 lib1910 lib1911 lib1912 lib1913 \
lib1915 lib1916 lib1917 lib1918 lib1933 lib1934 lib1935 lib1936 \
lib1948 \
lib3010
chkdecimalpoint_SOURCES = chkdecimalpoint.c ../../lib/mprintf.c \
......@@ -699,6 +700,10 @@ lib1936_SOURCES = lib1936.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1936_LDADD = $(TESTUTIL_LIBS)
lib1936_CPPFLAGS = $(AM_CPPFLAGS)
lib1948_SOURCES = lib1948.c $(SUPPORTFILES)
lib1948_LDADD = $(TESTUTIL_LIBS)
lib1948_CPPFLAGS = $(AM_CPPFLAGS)
lib3010_SOURCES = lib3010.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib3010_LDADD = $(TESTUTIL_LIBS)
lib3010_CPPFLAGS = $(AM_CPPFLAGS)
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
typedef struct
{
char *buf;
size_t len;
} put_buffer;
static size_t put_callback(char *ptr, size_t size, size_t nmemb, void *stream)
{
put_buffer *putdata = (put_buffer *)stream;
size_t totalsize = size * nmemb;
size_t tocopy = (putdata->len < totalsize) ? putdata->len : totalsize;
memcpy(ptr, putdata->buf, tocopy);
putdata->len -= tocopy;
putdata->buf += tocopy;
return tocopy;
}
int test(char *URL)
{
CURL *curl;
CURLcode res = CURLE_OUT_OF_MEMORY;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
const char *testput = "This is test PUT data\n";
put_buffer pbuf;
/* PUT */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, put_callback);
pbuf.buf = (char *)testput;
pbuf.len = strlen(testput);
curl_easy_setopt(curl, CURLOPT_READDATA, &pbuf);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testput));
res = curl_easy_setopt(curl, CURLOPT_URL, URL);
if(!res)
res = curl_easy_perform(curl);
if(!res) {
/* POST */
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, testput);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(testput));
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return (int)res;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册