From 5953fde6be086a653e16c4f31abc49f99ea625db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 11 Mar 2023 11:54:10 +0800 Subject: [PATCH] fix: hostname check --- server.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server.c b/server.c index ebce823..f4294b1 100644 --- a/server.c +++ b/server.c @@ -156,19 +156,23 @@ static void accept_request(void *cli) { } } int content_length = 0; + int host_chk_passed = !(uintptr_t)hostnameport; cgi &= ((st.st_mode & S_IXUSR) || (st.st_mode & S_IXGRP) || (st.st_mode & S_IXOTH)); while((numchars > 0) && strcmp("\n", buf)) { numchars = get_line(client, buf, sizeof(buf)); if(!content_length && !strncasecmp(buf, "Content-Length: ", 16)) { content_length = atoi(buf + 16); } - else if(hostnameport && !strncasecmp(buf, "Host: ", 6)) { + else if(!host_chk_passed && !strncasecmp(buf, "Host: ", 6)) { if(strncasecmp(buf+6, hostnameport, strlen(hostnameport))) { forbidden(client); - goto DISCARD_AND_CLOSE; + host_chk_passed = 0; + break; } + host_chk_passed = 1; } } + if(!host_chk_passed) break; if(method_type == POST && content_length == -1) bad_request(client); else if(!cgi) serve_file(client, path); else {