curl: fix some security problems
[openwrt/staging/pepe2k.git] / package / network / utils / curl / patches / 111-CVE-2018-1000120.patch
1 From a6ae0fbe9c50733e0f645f5bd16e1db38c592c3d Mon Sep 17 00:00:00 2001
2 From: Daniel Stenberg <daniel@haxx.se>
3 Date: Wed, 31 Jan 2018 08:40:11 +0100
4 Subject: [PATCH] FTP: reject path components with control codes
5
6 Refuse to operate when given path components featuring byte values lower
7 than 32.
8
9 Previously, inserting a %00 sequence early in the directory part when
10 using the 'singlecwd' ftp method could make curl write a zero byte
11 outside of the allocated buffer.
12
13 Test case 340 verifies.
14
15 CVE-2018-1000120
16 Reported-by: Duy Phan Thanh
17 Bug: https://curl.haxx.se/docs/adv_2018-9cd6.html
18 ---
19 lib/ftp.c | 8 ++++----
20 tests/data/Makefile.inc | 3 +++
21 tests/data/test340 | 40 ++++++++++++++++++++++++++++++++++++++++
22 3 files changed, 47 insertions(+), 4 deletions(-)
23 create mode 100644 tests/data/test340
24
25 --- a/lib/ftp.c
26 +++ b/lib/ftp.c
27 @@ -3235,7 +3235,7 @@ static CURLcode ftp_done(struct connectd
28
29 if(!result)
30 /* get the "raw" path */
31 - result = Curl_urldecode(data, path_to_use, 0, &path, NULL, FALSE);
32 + result = Curl_urldecode(data, path_to_use, 0, &path, NULL, TRUE);
33 if(result) {
34 /* We can limp along anyway (and should try to since we may already be in
35 * the error path) */
36 @@ -4241,7 +4241,7 @@ CURLcode ftp_parse_url_path(struct conne
37 result = Curl_urldecode(conn->data, slash_pos ? cur_pos : "/",
38 slash_pos ? dirlen : 1,
39 &ftpc->dirs[0], NULL,
40 - FALSE);
41 + TRUE);
42 if(result) {
43 freedirs(ftpc);
44 return result;
45 @@ -4349,7 +4349,7 @@ CURLcode ftp_parse_url_path(struct conne
46 size_t dlen;
47 char *path;
48 CURLcode result =
49 - Curl_urldecode(conn->data, data->state.path, 0, &path, &dlen, FALSE);
50 + Curl_urldecode(conn->data, data->state.path, 0, &path, &dlen, TRUE);
51 if(result) {
52 freedirs(ftpc);
53 return result;