Zebediah Figura : http.sys: Send a 400 Bad Request response when an invalid request is received.

Alexandre Julliard julliard at winehq.org
Wed Aug 28 18:23:20 CDT 2019


Module: wine
Branch: master
Commit: 980a56c61b73cb33b764083219d0dc0dc1e834ae
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=980a56c61b73cb33b764083219d0dc0dc1e834ae

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Tue Aug 27 16:43:00 2019 -0500

http.sys: Send a 400 Bad Request response when an invalid request is received.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 51881dd..4115afc 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);
     }
 }




More information about the wine-cvs mailing list