]> granicus.if.org Git - curl/commitdiff
readwrite: make sure excess reads don't go beyond buffer end
authorDaniel Stenberg <daniel@haxx.se>
Thu, 8 Mar 2018 09:33:16 +0000 (10:33 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 12 Mar 2018 06:47:07 +0000 (07:47 +0100)
CVE-2018-1000122
Bug: https://curl.haxx.se/docs/adv_2018-b047.html

Detected by OSS-fuzz

lib/transfer.c

index c46ac25f4ba7335aab2f0a1f587bd6fc4288c291..fd9af315594cd3463593807ec10bdf844be1afdd 100644 (file)
@@ -808,10 +808,15 @@ static CURLcode readwrite_data(struct Curl_easy *data,
 
     } /* if(!header and data to read) */
 
-    if(conn->handler->readwrite &&
-       (excess > 0 && !conn->bits.stream_was_rewound)) {
+    if(conn->handler->readwrite && excess && !conn->bits.stream_was_rewound) {
       /* Parse the excess data */
       k->str += nread;
+
+      if(&k->str[excess] > &k->buf[data->set.buffer_size]) {
+        /* the excess amount was too excessive(!), make sure
+           it doesn't read out of buffer */
+        excess = &k->buf[data->set.buffer_size] - k->str;
+      }
       nread = (ssize_t)excess;
 
       result = conn->handler->readwrite(data, conn, &nread, &readmore);