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') 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 From 71995aa7bab0198b3977f33d16ca34e4f628ec3d Mon Sep 17 00:00:00 2001 From: ame Date: Sat, 9 Aug 2025 04:26:08 -0500 Subject: dont override Content-Type --- src/net/lua.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/net') diff --git a/src/net/lua.c b/src/net/lua.c index d6bba65..2e46943 100644 --- a/src/net/lua.c +++ b/src/net/lua.c @@ -228,8 +228,11 @@ int l_sendfile(lua_State* L){ p_fatal("missing permissions"); } + lua_pushstring(L, "Content-Type"); + lua_gettable(L, header); + char* ext = strrchr(path, '.'); - if(ext && mime_type != NULL){ + if(lua_isnil(L, -1) && ext && mime_type != NULL){ char* content_type = map_get(mime_type, ext + 1); if(content_type) -- cgit v1.2.3 From 432f7792d12dadc3adb605c018176bbc7359b503 Mon Sep 17 00:00:00 2001 From: ame Date: Tue, 12 Aug 2025 21:54:57 -0500 Subject: support percent encoding --- src/net/util.c | 26 ++++++++++++++++++++++++++ src/net/util.h | 3 +++ 2 files changed, 29 insertions(+) (limited to 'src/net') diff --git a/src/net/util.c b/src/net/util.c index b41f0ed..92e538b 100644 --- a/src/net/util.c +++ b/src/net/util.c @@ -522,3 +522,29 @@ int net_error(int fd, int code){ send(fd, out, strlen(out), MSG_NOSIGNAL); return 0; } + +int percent_decode(str* input, str** _output){ + str* output = str_init(""); + + //could maybe make this better by using memmem to find occurrences of % + for(int i = 0; i <= input->len; i++){ + if(input->c[i] == '%' && input->len - i >= 3){ + str* hex = str_initfl(input->c + i + 1, 2); + + //casting a long to a char pointer is a horrible idea + long c = strtol(hex->c, NULL, 16); + if(c == 0){ + *_output = output; + return 1; + } + + str_pushl(output, ((char*)&c), 1); + str_free(hex); + i += 2; + } else { + str_pushl(output, input->c + i, 1); + } + } + *_output = output; + return 0; +} diff --git a/src/net/util.h b/src/net/util.h index cfac065..b8bc824 100644 --- a/src/net/util.h +++ b/src/net/util.h @@ -56,3 +56,6 @@ int match_param(char* path, char* match, parray_t* arr); void parse_mimetypes(); int net_error(int fd, int code); + +int percent_decode(str* input, str** _output); + -- cgit v1.2.3 From 70dcbc67382084d924d353f9c741cd8c0e46cb0f Mon Sep 17 00:00:00 2001 From: ame Date: Tue, 12 Aug 2025 22:02:18 -0500 Subject: mem leak oops --- src/net/util.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/net') diff --git a/src/net/util.c b/src/net/util.c index 92e538b..78e3043 100644 --- a/src/net/util.c +++ b/src/net/util.c @@ -534,6 +534,7 @@ int percent_decode(str* input, str** _output){ //casting a long to a char pointer is a horrible idea long c = strtol(hex->c, NULL, 16); if(c == 0){ + str_free(hex); *_output = output; return 1; } -- cgit v1.2.3