100-file-on-Windows-refuse-paths-that-start-with.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. From 1b71bc532bde8621fd3260843f8197182a467ff2 Mon Sep 17 00:00:00 2001
  2. From: Daniel Stenberg <daniel@haxx.se>
  3. Date: Thu, 7 Nov 2019 10:13:01 +0100
  4. Subject: [PATCH] file: on Windows, refuse paths that start with \\
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ... as that might cause an unexpected SMB connection to a given host
  9. name.
  10. Reported-by: Fernando Muñoz
  11. CVE-2019-15601
  12. Bug: https://curl.haxx.se/docs/CVE-2019-15601.html
  13. Signed-off-by: Petr Štetiar <ynezz@true.cz>
  14. ---
  15. lib/file.c | 6 ++++--
  16. 1 file changed, 4 insertions(+), 2 deletions(-)
  17. diff --git a/lib/file.c b/lib/file.c
  18. index d349cd9241cd..166931d7f1ba 100644
  19. --- a/lib/file.c
  20. +++ b/lib/file.c
  21. @@ -136,7 +136,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
  22. struct Curl_easy *data = conn->data;
  23. char *real_path;
  24. struct FILEPROTO *file = data->req.protop;
  25. - int fd;
  26. + int fd = -1;
  27. #ifdef DOS_FILESYSTEM
  28. size_t i;
  29. char *actual_path;
  30. @@ -181,7 +181,9 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
  31. return CURLE_URL_MALFORMAT;
  32. }
  33. - fd = open_readonly(actual_path, O_RDONLY|O_BINARY);
  34. + if(strncmp("\\\\", actual_path, 2))
  35. + /* refuse to open path that starts with two backslashes */
  36. + fd = open_readonly(actual_path, O_RDONLY|O_BINARY);
  37. file->path = actual_path;
  38. #else
  39. if(memchr(real_path, 0, real_path_len)) {