108-CVE-2017-8817.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. From 0acc0c7c120afa6d60bfc7932c04361720b6e74d Mon Sep 17 00:00:00 2001
  2. From: Daniel Stenberg <daniel@haxx.se>
  3. Date: Fri, 10 Nov 2017 08:52:45 +0100
  4. Subject: [PATCH] wildcardmatch: fix heap buffer overflow in setcharset
  5. The code would previous read beyond the end of the pattern string if the
  6. match pattern ends with an open bracket when the default pattern
  7. matching function is used.
  8. Detected by OSS-Fuzz:
  9. https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4161
  10. CVE-2017-8817
  11. Bug: https://curl.haxx.se/docs/adv_2017-ae72.html
  12. ---
  13. lib/curl_fnmatch.c | 9 +++------
  14. tests/data/Makefile.inc | 2 +-
  15. tests/data/test1163 | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
  16. 3 files changed, 56 insertions(+), 7 deletions(-)
  17. create mode 100644 tests/data/test1163
  18. --- a/lib/curl_fnmatch.c
  19. +++ b/lib/curl_fnmatch.c
  20. @@ -133,6 +133,9 @@ static int setcharset(unsigned char **p,
  21. unsigned char c;
  22. for(;;) {
  23. c = **p;
  24. + if(!c)
  25. + return SETCHARSET_FAIL;
  26. +
  27. switch(state) {
  28. case CURLFNM_SCHS_DEFAULT:
  29. if(ISALNUM(c)) { /* ASCII value */
  30. @@ -197,9 +200,6 @@ static int setcharset(unsigned char **p,
  31. else
  32. return SETCHARSET_FAIL;
  33. }
  34. - else if(c == '\0') {
  35. - return SETCHARSET_FAIL;
  36. - }
  37. else {
  38. charset[c] = 1;
  39. (*p)++;
  40. @@ -278,9 +278,6 @@ static int setcharset(unsigned char **p,
  41. else if(c == ']') {
  42. return SETCHARSET_OK;
  43. }
  44. - else if(c == '\0') {
  45. - return SETCHARSET_FAIL;
  46. - }
  47. else if(ISPRINT(c)) {
  48. charset[c] = 1;
  49. (*p)++;
  50. --- a/tests/data/Makefile.inc
  51. +++ b/tests/data/Makefile.inc
  52. @@ -121,6 +121,7 @@ test1120 test1121 test1122 test1123 test
  53. test1128 test1129 test1130 test1131 test1132 test1133 test1134 test1135 \
  54. test1136 test1137 test1138 test1139 test1140 test1141 test1142 test1143 \
  55. test1144 \
  56. +test1163 \
  57. test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
  58. test1208 test1209 test1210 test1211 test1212 test1213 test1214 test1215 \
  59. test1216 test1217 test1218 test1219 \
  60. --- /dev/null
  61. +++ b/tests/data/test1163
  62. @@ -0,0 +1,52 @@
  63. +<testcase>
  64. +<info>
  65. +<keywords>
  66. +FTP
  67. +RETR
  68. +LIST
  69. +wildcardmatch
  70. +ftplistparser
  71. +flaky
  72. +</keywords>
  73. +</info>
  74. +
  75. +#
  76. +# Server-side
  77. +<reply>
  78. +<data>
  79. +</data>
  80. +</reply>
  81. +
  82. +# Client-side
  83. +<client>
  84. +<server>
  85. +ftp
  86. +</server>
  87. +<tool>
  88. +lib576
  89. +</tool>
  90. +<name>
  91. +FTP wildcard with pattern ending with an open-bracket
  92. +</name>
  93. +<command>
  94. +"ftp://%HOSTIP:%FTPPORT/fully_simulated/DOS/*[]["
  95. +</command>
  96. +</client>
  97. +<verify>
  98. +<protocol>
  99. +USER anonymous
  100. +PASS ftp@example.com
  101. +PWD
  102. +CWD fully_simulated
  103. +CWD DOS
  104. +EPSV
  105. +TYPE A
  106. +LIST
  107. +QUIT
  108. +</protocol>
  109. +# 78 == CURLE_REMOTE_FILE_NOT_FOUND
  110. +<errorcode>
  111. +78
  112. +</errorcode>
  113. +</verify>
  114. +</testcase>