diff --git a/Makefile b/Makefile index 933a711..c2f1a61 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CC=clang CFLAGS=-Wall -Wextra -Wpedantic -Werror -std=c23 -D_POSIX_C_SOURCE=200809L -pthread -O2 -CFLAGS+=-Og -g -fsanitize=address,undefined +#CFLAGS+=-Og -g -fsanitize=address,undefined SRCS=main.c threadpool.c util.c server.c http.c OBJS=$(SRCS:%.c=bin/%.o) diff --git a/main.c b/main.c index ab9612f..30aad93 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ * - main.c: Argument parsing and high-level control * - http.c: HTTP request parsing and response formatting * - server.c: Abstraction over sockets - * - threadpool.c: Thread pool and wokr queue implementation + * - threadpool.c: Thread pool and woker queue implementation * - util.c: Misc. utility functions */ #include "http.h" @@ -279,20 +279,20 @@ static void handle_put_request(FILE *conn, HTTPRequest *restrict req) { (size_t) content_length < sizeof(read_buff) ? (size_t) content_length : sizeof(read_buff), conn); - if (ferror(conn) || write(temp_fd, read_buff, read_size) < 0) { - write_audit_log_entry(req, 500); - send_simple_response(conn, 500); - close(temp_fd); - unlink(temp_file); - return; - } else if (feof(conn)) { + content_length -= read_size; + if (feof(conn) && content_length) { write_audit_log_entry(req, 400); send_simple_response(conn, 400); close(temp_fd); unlink(temp_file); return; + } else if (ferror(conn) || write(temp_fd, read_buff, read_size) < 0) { + write_audit_log_entry(req, 500); + send_simple_response(conn, 500); + close(temp_fd); + unlink(temp_file); + return; } - content_length -= read_size; } close(temp_fd); int status;