From b5003279693384d36919177a54af27d3dbed59d5 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Mon, 3 Sep 2018 16:41:17 -0400 Subject: [PATCH] Fix buffer overrun in content length usage --- common/socket_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/socket_helper.c b/common/socket_helper.c index 897edf5..886c8d2 100644 --- a/common/socket_helper.c +++ b/common/socket_helper.c @@ -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) {