111-CVE-2018-1000120.patch 1.9 KB

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