From ce33e309ad9dd3321e42ae623ac12fd739957259 Mon Sep 17 00:00:00 2001 From: ame Date: Tue, 5 Aug 2025 15:07:31 -0500 Subject: add length after check, duh --- src/net/util.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/net/util.c') diff --git a/src/net/util.c b/src/net/util.c index 3e91c7c..b41f0ed 100644 --- a/src/net/util.c +++ b/src/net/util.c @@ -16,16 +16,16 @@ int64_t recv_header(int client_fd, char** _buffer, char** header_eof){ return -1; } - if((len += n) >= MAX_HEADER_SIZE){ - return -2; - } - // search the last 4 characters too if they exist // this could probably be changed to 3 - int64_t start_len = len - 4 > 0 ? len - 4 : 0; + int64_t start_len = len - 4 > 0 ? len - 4 : len; int64_t search_end = len - 4 > 0 ? n + 4 : n; if((*header_eof = memmem(buffer + start_len, search_end, "\r\n\r\n", 4)) != NULL){ - return len; + return len + n; + } + + if((len += n) >= MAX_HEADER_SIZE){ + return -2; } buffer = realloc(buffer, sizeof* buffer * (len + BUFFER_SIZE + 1)); -- cgit v1.2.3