105-CVE-2017-1000254.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. From 29b251362e1839d7094993edbed8f9467069773f Mon Sep 17 00:00:00 2001
  2. From: Daniel Stenberg <daniel@haxx.se>
  3. Date: Mon, 25 Sep 2017 00:35:22 +0200
  4. Subject: [PATCH] FTP: zero terminate the entry path even on bad input
  5. ... a single double quote could leave the entry path buffer without a zero
  6. terminating byte. CVE-2017-1000254
  7. Test 1152 added to verify.
  8. Reported-by: Max Dymond
  9. Bug: https://curl.haxx.se/docs/adv_20171004.html
  10. ---
  11. lib/ftp.c | 7 ++++--
  12. tests/data/Makefile.inc | 1 +
  13. tests/data/test1152 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
  14. 3 files changed, 67 insertions(+), 2 deletions(-)
  15. create mode 100644 tests/data/test1152
  16. --- a/lib/ftp.c
  17. +++ b/lib/ftp.c
  18. @@ -2825,6 +2825,7 @@ static CURLcode ftp_statemach_act(struct
  19. char *ptr=&data->state.buffer[4]; /* start on the first letter */
  20. char *dir;
  21. char *store;
  22. + bool entry_extracted = FALSE;
  23. dir = malloc(nread + 1);
  24. if(!dir)
  25. @@ -2856,7 +2857,7 @@ static CURLcode ftp_statemach_act(struct
  26. }
  27. else {
  28. /* end of path */
  29. - *store = '\0'; /* zero terminate */
  30. + entry_extracted = TRUE;
  31. break; /* get out of this loop */
  32. }
  33. }
  34. @@ -2865,7 +2866,9 @@ static CURLcode ftp_statemach_act(struct
  35. store++;
  36. ptr++;
  37. }
  38. -
  39. + *store = '\0'; /* zero terminate */
  40. + }
  41. + if(entry_extracted) {
  42. /* If the path name does not look like an absolute path (i.e.: it
  43. does not start with a '/'), we probably need some server-dependent
  44. adjustments. For example, this is the case when connecting to