diff --git a/src/tiny_http/tiny_http_server_lib.c b/src/tiny_http/tiny_http_server_lib.c index c1631eb..7bfeb4f 100644 --- a/src/tiny_http/tiny_http_server_lib.c +++ b/src/tiny_http/tiny_http_server_lib.c @@ -305,6 +305,7 @@ enum parse_http_request_status parse_http_request_headers( } enum parse_http_request_status parse_http_request_line_from_packet( + const http_server_settings *const settings, const uint8_t *const http_packet, const size_t http_packet_len, http_request *request, @@ -335,7 +336,9 @@ enum parse_http_request_status parse_http_request_line_from_packet( printf("request method: %d", request->method); #endif - for (int iter_cnt = 0; *ptr < http_packet_len && iter_cnt < MAX_URL_LENGTH; (*ptr)++, iter_cnt++) { + for (int iter_cnt = 0; + *ptr < http_packet_len && iter_cnt < settings->max_url_length; + (*ptr)++, iter_cnt++) { if (http_packet[(*ptr)] == ' ') { request->url = strndup((char *) &http_packet[start_uri], *ptr - start_uri); (*ptr)++; @@ -403,7 +406,7 @@ http_request *parse_http_request( size_t ptr = 0; const enum parse_http_request_status request_line_parse_status = - parse_http_request_line_from_packet(http_packet, http_packet_len, request, &ptr); + parse_http_request_line_from_packet(settings, http_packet, http_packet_len, request, &ptr); if (request_line_parse_status != PARSE_OK) { destroy_http_request(request); return nullptr; diff --git a/src/tiny_http/tiny_http_server_lib.h b/src/tiny_http/tiny_http_server_lib.h index f7f7a00..2d9c649 100644 --- a/src/tiny_http/tiny_http_server_lib.h +++ b/src/tiny_http/tiny_http_server_lib.h @@ -7,10 +7,6 @@ #include #include -#define MAX_URL_LENGTH 8000 -#define MAX_HTTP_HEADER_NAME_LENGTH 8000 -#define MAX_HTTP_HEADER_VALUE_LENGTH 8000 - typedef enum http_version { HTTP_1_0 = 1, } http_version; @@ -51,6 +47,7 @@ typedef struct http_server_settings { size_t max_header_name_length; size_t max_header_value_length; size_t max_body_length; + size_t max_url_length; } http_server_settings; /** diff --git a/test/assert_tiny_http_server_lib.c b/test/assert_tiny_http_server_lib.c index 396a054..e5d69ff 100644 --- a/test/assert_tiny_http_server_lib.c +++ b/test/assert_tiny_http_server_lib.c @@ -15,6 +15,7 @@ http_server_settings settings = { .max_header_name_length = 256, .max_header_value_length = 512, .max_body_length = 1024 * 1024 * 8, // 8M + .max_url_length = 8000 // NOTE: should be ~2000, but meh the standards doesn't have a comment on it, SEO says 2000 }; void test_request_parse_get_root_curl(void) {