113-CVE-2018-1000122.patch 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. From d70b74d6f893947aa22d3f14df10f92a8c349388 Mon Sep 17 00:00:00 2001
  2. From: Daniel Stenberg <daniel@haxx.se>
  3. Date: Thu, 8 Mar 2018 10:33:16 +0100
  4. Subject: [PATCH] readwrite: make sure excess reads don't go beyond buffer end
  5. CVE-2018-1000122
  6. Bug: https://curl.haxx.se/docs/adv_2018-b047.html
  7. Detected by OSS-fuzz
  8. ---
  9. lib/transfer.c | 9 +++++++--
  10. 1 file changed, 7 insertions(+), 2 deletions(-)
  11. --- a/lib/transfer.c
  12. +++ b/lib/transfer.c
  13. @@ -791,10 +791,15 @@ static CURLcode readwrite_data(struct Cu
  14. } /* if(!header and data to read) */
  15. - if(conn->handler->readwrite &&
  16. - (excess > 0 && !conn->bits.stream_was_rewound)) {
  17. + if(conn->handler->readwrite && excess && !conn->bits.stream_was_rewound) {
  18. /* Parse the excess data */
  19. k->str += nread;
  20. +
  21. + if(&k->str[excess] > &k->buf[data->set.buffer_size]) {
  22. + /* the excess amount was too excessive(!), make sure
  23. + it doesn't read out of buffer */
  24. + excess = &k->buf[data->set.buffer_size] - k->str;
  25. + }
  26. nread = (ssize_t)excess;
  27. result = conn->handler->readwrite(data, conn, &nread, &readmore);