[PATCH 3/4] http.sys: Send a 400 Bad Request response when an invalid request is received.
Zebediah Figura
z.figura12 at gmail.com
Tue Aug 27 16:43:00 CDT 2019
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
dlls/http.sys/http.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/dlls/http.sys/http.c b/dlls/http.sys/http.c
index 51881ddcd59..4115afc8672 100644
--- a/dlls/http.sys/http.c
+++ b/dlls/http.sys/http.c
@@ -920,6 +920,35 @@ static int parse_request(struct connection *conn)
return 1;
}
+static void format_date(char *buffer)
+{
+ static const char day_names[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+ static const char month_names[12][4] =
+ {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+ SYSTEMTIME date;
+ GetSystemTime(&date);
+ sprintf(buffer + strlen(buffer), "Date: %s, %02u %s %u %02u:%02u:%02u GMT\r\n",
+ day_names[date.wDayOfWeek], date.wDay, month_names[date.wMonth - 1],
+ date.wYear, date.wHour, date.wMinute, date.wSecond);
+}
+
+/* Send a 400 Bad Request response. */
+static void send_400(struct connection *conn)
+{
+ static const char response_header[] = "HTTP/1.1 400 Bad Request\r\n";
+ static const char response_body[] =
+ "Content-Type: text/html; charset=utf-8\r\n"
+ "Content-Language: en\r\n"
+ "Connection: close\r\n";
+ char buffer[sizeof(response_header) + sizeof(response_body) + 37];
+
+ strcpy(buffer, response_header);
+ format_date(buffer + strlen(buffer));
+ strcat(buffer, response_body);
+ if (send(conn->socket, buffer, strlen(buffer), 0) < 0)
+ ERR("Failed to send 400 response, error %u.\n", WSAGetLastError());
+}
+
static void receive_data(struct connection *conn)
{
int len, ret;
@@ -977,6 +1006,7 @@ static void receive_data(struct connection *conn)
else if (ret < 0)
{
WARN("Failed to parse request; shutting down connection.\n");
+ send_400(conn);
close_connection(conn);
}
}
--
2.22.0
More information about the wine-devel
mailing list