Skip to content

Commit b930b8e

Browse files
LoopinFooldeanberris
authored andcommitted
Fix chunk and content-length encoding (cpp-netlib#759)
* The entire body has already been placed in partial_parsed, so don't direct the callback to append any more data * Cleaned up indentation. Don't potentially access memory beyond the end of the string buffer. In the case of a partial chunk, exit the loop. Continuing to search for crlf in the middle of a binary data chunk can result in an infinite loop, and wasn't the right logic.
1 parent cef6472 commit b930b8e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

boost/network/protocol/http/client/connection/async_protocol_handler.hpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -361,22 +361,23 @@ struct http_async_protocol_handler {
361361
for (typename string_type::const_iterator iter =
362362
std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end());
363363
iter != partial_parsed.end();
364-
iter =
365-
std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end())) {
364+
iter = std::search(begin, partial_parsed.end(), crlf.begin(), crlf.end())) {
366365
string_type line(begin, iter);
367366
if (line.empty()) {
368-
std::advance(iter, 2);
369-
begin = iter;
370-
continue;
367+
std::advance(iter, 2);
368+
begin = iter;
369+
continue;
371370
}
372371
std::stringstream stream(line);
373372
int len;
374373
stream >> std::hex >> len;
375374
std::advance(iter, 2);
376375
if (!len) return true;
377376
if (len <= partial_parsed.end() - iter) {
378-
std::advance(iter, len + 2);
379-
}
377+
std::advance(iter, len);
378+
} else {
379+
return false;
380+
}
380381
begin = iter;
381382
}
382383
return false;
@@ -391,7 +392,7 @@ struct http_async_protocol_handler {
391392
partial_parsed.append(part_begin, it);
392393
part_begin = part.begin();
393394
if (check_parse_body_complete()) {
394-
callback(boost::asio::error::eof, bytes);
395+
callback(boost::asio::error::eof, 0);
395396
} else {
396397
delegate_->read_some(
397398
boost::asio::mutable_buffers_1(part.data(), part.size()), callback);

0 commit comments

Comments
 (0)