Fix buffer overrun in content length usage

This commit is contained in:
Nick Krichevsky 2018-09-03 16:41:17 -04:00
parent 74d23ebebe
commit b500327969

View file

@ -136,7 +136,7 @@ static char *read_body_by_content_length(int socket_fd, long content_length) {
int bytes_read = 0;
int write_offset = 0;
while ((total_bytes_read += bytes_read = read(socket_fd, buffer, content_length)) <= content_length && bytes_read > 0) {
memcpy(result + write_offset, buffer, content_length);
memcpy(result + write_offset, buffer, bytes_read);
write_offset += bytes_read;
// If we've read exactly the number of bytes we need to, we don't need to wait for more data.
if (total_bytes_read == content_length) {