Skip to content

Commit 95a6431

Browse files
committed
Cherry pick dangling data pointer fix for curl
1 parent 966bc0d commit 95a6431

3 files changed

+195
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
From c45360d4633850839bb9c2d77dbf8a8285e9ad49 Mon Sep 17 00:00:00 2001
2+
From: Marian Klymov <nekto1989@gmail.com>
3+
Date: Sat, 2 Jun 2018 23:52:56 +0300
4+
Subject: [PATCH] cppcheck: fix warnings
5+
6+
- Get rid of variable that was generating false positive warning
7+
(unitialized)
8+
9+
- Fix issues in tests
10+
11+
- Reduce scope of several variables all over
12+
13+
etc
14+
15+
Closes #2631
16+
---
17+
lib/base64.c | 3 +--
18+
lib/connect.c | 6 +-----
19+
lib/content_encoding.c | 8 +++-----
20+
lib/cookie.c | 7 +++----
21+
lib/curl_sasl.c | 3 +--
22+
lib/dict.c | 6 +++---
23+
lib/escape.c | 6 ++----
24+
lib/file.c | 6 +++---
25+
lib/formdata.c | 3 +--
26+
lib/ftp.c | 13 ++++++-------
27+
lib/hash.c | 11 ++++-------
28+
lib/http.c | 10 ++++------
29+
lib/http_proxy.c | 2 +-
30+
lib/imap.c | 8 ++++----
31+
lib/mime.c | 32 +++++++++++---------------------
32+
lib/multi.c | 7 +++----
33+
lib/pingpong.c | 3 +--
34+
lib/pop3.c | 4 ++--
35+
lib/progress.c | 39 ++++++++++++++++++++-------------------
36+
lib/rtsp.c | 6 ++----
37+
lib/select.c | 8 +++++---
38+
lib/sendf.c | 2 +-
39+
lib/sendf.h | 4 ++--
40+
lib/sha256.c | 12 ++++++------
41+
lib/smtp.c | 2 +-
42+
lib/socks.c | 8 ++++----
43+
lib/splay.c | 3 +--
44+
lib/telnet.c | 32 ++++++++++++++++----------------
45+
lib/tftp.c | 16 +++++++---------
46+
lib/transfer.c | 2 +-
47+
lib/url.c | 15 +++++++--------
48+
lib/vauth/digest.c | 6 +++---
49+
src/tool_cb_dbg.c | 10 +++++-----
50+
src/tool_cb_prg.c | 12 ++++++------
51+
src/tool_formparse.c | 5 ++---
52+
src/tool_getparam.c | 6 ++----
53+
src/tool_libinfo.c | 2 +-
54+
src/tool_msgs.c | 2 +-
55+
src/tool_paramhlp.c | 10 +++++-----
56+
src/tool_parsecfg.c | 8 +++-----
57+
src/tool_urlglob.c | 2 +-
58+
src/tool_writeout.c | 4 ++--
59+
tests/libtest/lib1537.c | 15 +++++----------
60+
tests/libtest/lib1554.c | 3 +--
61+
tests/libtest/lib1900.c | 8 ++++----
62+
tests/libtest/lib506.c | 2 +-
63+
tests/libtest/lib512.c | 6 ++----
64+
tests/libtest/lib556.c | 2 +-
65+
tests/libtest/lib579.c | 3 +--
66+
tests/libtest/lib586.c | 2 +-
67+
tests/libtest/testtrace.c | 2 +-
68+
tests/server/getpart.c | 2 +-
69+
tests/server/rtspd.c | 18 +++++++-----------
70+
tests/server/sockfilt.c | 29 ++++++++++++-----------------
71+
tests/server/sws.c | 5 ++---
72+
tests/server/testpart.c | 6 +++---
73+
tests/server/tftpd.c | 16 +++++++---------
74+
tests/server/util.c | 5 ++---
75+
tests/unit/unit1300.c | 2 +-
76+
tests/unit/unit1303.c | 2 +-
77+
tests/unit/unit1307.c | 4 ++--
78+
61 files changed, 213 insertions(+), 273 deletions(-)
79+
80+
diff --git a/lib/connect.c b/lib/connect.c
81+
index 1a27ae1353..12ae817e31 100644
82+
--- a/lib/connect.c
83+
+++ b/lib/connect.c
84+
@@ -1237,8 +1237,6 @@ static int conn_is_conn(struct connectdata *conn, void *param)
85+
curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
86+
struct connectdata **connp)
87+
{
88+
- curl_socket_t sockfd;
89+
-
90+
DEBUGASSERT(data);
91+
92+
/* this works for an easy handle:
93+
@@ -1264,12 +1262,10 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
94+
if(connp)
95+
/* only store this if the caller cares for it */
96+
*connp = c;
97+
- sockfd = c->sock[FIRSTSOCKET];
98+
+ return c->sock[FIRSTSOCKET];
99+
}
100+
else
101+
return CURL_SOCKET_BAD;
102+
-
103+
- return sockfd;
104+
}
105+
106+
/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
From 2c15693a3c355d8296a1828123a864397296460b Mon Sep 17 00:00:00 2001
2+
From: Daniel Stenberg <daniel@haxx.se>
3+
Date: Wed, 20 Jun 2018 23:00:36 +0200
4+
Subject: [PATCH] url: fix dangling conn->data pointer
5+
6+
By masking sure to use the *current* easy handle with extracted
7+
connections from the cache, and make sure to NULLify the ->data pointer
8+
when the connection is put into the cache to make this mistake easier to
9+
detect in the future.
10+
11+
Reported-by: Will Dietz
12+
Fixes #2669
13+
Closes #2672
14+
---
15+
lib/conncache.c | 3 ++-
16+
lib/connect.c | 6 ++++--
17+
lib/url.c | 2 +-
18+
3 files changed, 7 insertions(+), 4 deletions(-)
19+
20+
diff --git a/lib/conncache.c b/lib/conncache.c
21+
index 6bd06582a6..0665429154 100644
22+
--- a/lib/conncache.c
23+
+++ b/lib/conncache.c
24+
@@ -6,7 +6,7 @@
25+
* \___|\___/|_| \_\_____|
26+
*
27+
* Copyright (C) 2012 - 2016, Linus Nielsen Feltzing, <linus@haxx.se>
28+
- * Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
29+
+ * Copyright (C) 2012 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
30+
*
31+
* This software is licensed as described in the file COPYING, which
32+
* you should have received as part of this distribution. The terms
33+
@@ -451,6 +451,7 @@ bool Curl_conncache_return_conn(struct connectdata *conn)
34+
}
35+
CONN_LOCK(data);
36+
conn->inuse = FALSE; /* Mark the connection unused */
37+
+ conn->data = NULL; /* no owner */
38+
CONN_UNLOCK(data);
39+
40+
return (conn_candidate == conn) ? FALSE : TRUE;
41+
diff --git a/lib/connect.c b/lib/connect.c
42+
index 12ae817e31..41f2202681 100644
43+
--- a/lib/connect.c
44+
+++ b/lib/connect.c
45+
@@ -5,7 +5,7 @@
46+
* | (__| |_| | _ <| |___
47+
* \___|\___/|_| \_\_____|
48+
*
49+
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
50+
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
51+
*
52+
* This software is licensed as described in the file COPYING, which
53+
* you should have received as part of this distribution. The terms
54+
@@ -1259,9 +1259,11 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
55+
return CURL_SOCKET_BAD;
56+
}
57+
58+
- if(connp)
59+
+ if(connp) {
60+
/* only store this if the caller cares for it */
61+
*connp = c;
62+
+ c->data = data;
63+
+ }
64+
return c->sock[FIRSTSOCKET];
65+
}
66+
else
67+
diff --git a/lib/url.c b/lib/url.c
68+
index d29eddaea7..0cab0a303d 100644
69+
--- a/lib/url.c
70+
+++ b/lib/url.c
71+
@@ -965,6 +965,7 @@ static bool extract_if_dead(struct connectdata *conn,
72+
use */
73+
bool dead;
74+
75+
+ conn->data = data;
76+
if(conn->handler->connection_check) {
77+
/* The protocol has a special method for checking the state of the
78+
connection. Use it to check if the connection is dead. */
79+
@@ -979,7 +980,6 @@ static bool extract_if_dead(struct connectdata *conn,
80+
}
81+
82+
if(dead) {
83+
- conn->data = data;
84+
infof(data, "Connection %ld seems to be dead!\n", conn->connection_id);
85+
Curl_conncache_remove_conn(conn, FALSE);
86+
return TRUE;

ports/curl/portfile.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ vcpkg_apply_patches(
1616
SOURCE_PATH ${SOURCE_PATH}
1717
PATCHES
1818
${CMAKE_CURRENT_LIST_DIR}/patches/0001-Adjust-CMake-for-vcpkg.patch
19+
# Remove after 7.61.0 release
20+
${CMAKE_CURRENT_LIST_DIR}/patches/0002-cppcheck-fix-warnings.patch
21+
${CMAKE_CURRENT_LIST_DIR}/patches/0003-url-fix-dangling-conn-data-pointer.patch
1922
)
2023

2124
# Run CMake build

0 commit comments

Comments
 (0)