diff options
| author | amelia squires <[email protected]> | 2024-10-02 11:54:33 -0500 |
|---|---|---|
| committer | amelia squires <[email protected]> | 2024-10-02 11:54:33 -0500 |
| commit | 7c920f7f22a26e377aa9eab0f56ca45caddf7217 (patch) | |
| tree | e5b22e3a47d50125e9050052f608d62f29d32003 /src/net | |
| parent | 39f7d8562e355d85e7795f7cd43b29ed12f9c58e (diff) | |
server errors
Diffstat (limited to 'src/net')
| -rw-r--r-- | src/net/util.c | 13 | ||||
| -rw-r--r-- | src/net/util.h | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/net/util.c b/src/net/util.c index 44a525b..150b8f9 100644 --- a/src/net/util.c +++ b/src/net/util.c @@ -63,6 +63,7 @@ int64_t recv_full_buffer(int client_fd, char** _buffer, int* header_eof, int* st return len; } +#define max_uri_len 2048 /** * @brief converts the request buffer into a parray_t * @@ -85,6 +86,11 @@ int parse_header(char* buffer, int header_eof, parray_t** _table){ item++; if(buffer[oi] == '\n') break; } else { + if(oi >= max_uri_len){ + *_table = table; + str_free(current); + return -2; + } str_pushl(current, buffer + oi, 1); } } @@ -418,3 +424,10 @@ void parse_mimetypes(){ //printf("done\n"); } + +int net_error(int fd, int code){ + char out[512] = {0}; + sprintf(out, "HTTP/1.1 %i %s\n\n", code, http_code(code)); + send(fd, out, strlen(out), 0); + return 0; +} diff --git a/src/net/util.h b/src/net/util.h index e592420..254cc32 100644 --- a/src/net/util.h +++ b/src/net/util.h @@ -53,3 +53,5 @@ parray_t* route_match(parray_t* paths, char* path, larray_t** params); int match_param(char* path, char* match, parray_t* arr); void parse_mimetypes(); + +int net_error(int fd, int code); |
