diff --git a/Makefile b/Makefile index ded7e31..933a711 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ # If set to 1, the autograder -BAD_ERROR_REPORTING_FOR_AUTOGRADER=1 +#BAD_ERROR_REPORTING_FOR_AUTOGRADER=1 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/http.c b/http.c index 005c31f..691de3d 100644 --- a/http.c +++ b/http.c @@ -52,11 +52,11 @@ const char *http_header_list_search(HTTPHeaderList *list, const char *key, const } #define MAX_REQUEST_LENGTH 16384 -#define MAX_METHOD_LENGTH 16 -#define MAX_URI_LENGTH 256 +#define MAX_METHOD_LENGTH 8 +#define MAX_URI_LENGTH 64 #define MAX_VERSION_LENGTH 3 -#define MAX_HEADER_KEY_LENGTH 2048 -#define MAX_HEADER_VALUE_LENGTH 2048 +#define MAX_HEADER_KEY_LENGTH 128 +#define MAX_HEADER_VALUE_LENGTH 128 #define RETURN_IF_READ_ERROR(s) \ if (ferror((s))) { \ @@ -76,7 +76,7 @@ static HTTPRequestParseResult parse_method_uri_line( #define S(s) S1(s) int nconv = fscanf(stream, // clang-format off - "%" S(MAX_METHOD_LENGTH) "[A-Z0-9]" + "%" S(MAX_METHOD_LENGTH) "[a-zA-Z]" "%c" "%" S(MAX_URI_LENGTH) "[^ \n\r]" "%c" diff --git a/main.c b/main.c index 8671588..ab9612f 100644 --- a/main.c +++ b/main.c @@ -264,7 +264,6 @@ static void handle_put_request(FILE *conn, HTTPRequest *restrict req) { if (content_length < 0) { write_audit_log_entry(req, 400); send_simple_response(conn, 400); - fclose(conn); return; } char temp_file[] = "temp_fileXXXXXX"; @@ -286,6 +285,12 @@ static void handle_put_request(FILE *conn, HTTPRequest *restrict req) { close(temp_fd); unlink(temp_file); return; + } else if (feof(conn)) { + write_audit_log_entry(req, 400); + send_simple_response(conn, 400); + close(temp_fd); + unlink(temp_file); + return; } content_length -= read_size; }