From 257f0d14893a491786bccb34ecc847f74edd47c6 Mon Sep 17 00:00:00 2001 From: Andreas Wellving Date: Mon, 22 Oct 2018 13:01:11 +0200 Subject: [PATCH] FTP: reject path components with control codes Refuse to operate when given path components featuring byte values lower than 32. Previously, inserting a %00 sequence early in the directory part when using the 'singlecwd' ftp method could make curl write a zero byte outside of the allocated buffer. Test case 340 verifies. CVE-2018-1000120 Upstream-Status: Backport [https://curl.haxx.se/CVE-2018-1000120.patch] Reported-by: Duy Phan Thanh Bug: https://curl.haxx.se/docs/adv_2018-9cd6.html Signed-off-by: Andreas Wellving --- lib/ftp.c | 6 +++--- tests/data/Makefile.inc | 1 + tests/data/test340 | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tests/data/test340 diff --git a/lib/ftp.c b/lib/ftp.c index cab3699..0e28059 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -3236,7 +3236,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status, if(!result) /* get the "raw" path */ - result = Curl_urldecode(data, path_to_use, 0, &path, NULL, FALSE); + result = Curl_urldecode(data, path_to_use, 0, &path, NULL, TRUE); if(result) { /* We can limp along anyway (and should try to since we may already be in * the error path) */ @@ -4242,7 +4242,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn) result = Curl_urldecode(conn->data, slash_pos ? cur_pos : "/", slash_pos ? dirlen : 1, &ftpc->dirs[0], NULL, - FALSE); + TRUE); if(result) { freedirs(ftpc); return result; @@ -4350,7 +4350,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn) size_t dlen; char *path; CURLcode result = - Curl_urldecode(conn->data, data->state.path, 0, &path, &dlen, FALSE); + Curl_urldecode(conn->data, data->state.path, 0, &path, &dlen, TRUE); if(result) { freedirs(ftpc); return result; diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 135ba06..31e026f 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -57,6 +57,7 @@ test298 test299 test300 test301 test302 test303 test304 test305 test306 \ test307 test308 test309 test310 test311 test312 test313 \ test320 test321 test322 test323 test324 \ test325 \ +test340 \ test350 test351 test352 test353 test354 \ \ test400 test401 test402 test403 test404 test405 test406 test407 test408 \ diff --git a/tests/data/test340 b/tests/data/test340 new file mode 100644 index 0000000..d834d76 --- /dev/null +++ b/tests/data/test340 @@ -0,0 +1,40 @@ + + + +FTP +PASV +CWD +--ftp-method +singlecwd + + +# +# Server-side + + + +# Client-side + + +ftp + + +FTP using %00 in path with singlecwd + + +--ftp-method singlecwd ftp://%HOSTIP:%FTPPORT/%00first/second/third/340 + + + +# Verify data after the test has been "shot" + + +USER anonymous +PASS ftp@example.com +PWD + + +3 + + +