From c291b049c884db8d2e4b6f1ce9bfc1f20f9a4004 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 31 Jul 2020 15:46:51 -0400 Subject: [PATCH] fix: Properly close malformed requests --- runtime/include/http_response.h | 1 + runtime/src/sandbox.c | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/runtime/include/http_response.h b/runtime/include/http_response.h index 8814077..27b401f 100644 --- a/runtime/include/http_response.h +++ b/runtime/include/http_response.h @@ -11,6 +11,7 @@ #define HTTP_RESPONSE_200_OK "HTTP/1.1 200 OK\r\n" #define HTTP_RESPONSE_504_SERVICE_UNAVAILABLE "HTTP/1.1 504 Service Unavailable\r\n\r\n" +#define HTTP_RESPONSE_400_BAD_REQUEST "HTTP/1.1 400 Bad Request\r\n\r\n" #define HTTP_RESPONSE_CONTENT_LENGTH "Content-Length: " #define HTTP_RESPONSE_CONTENT_LENGTH_TERMINATOR "\r\n\r\n" /* content body follows this */ #define HTTP_RESPONSE_CONTENT_TYPE "Content-Type: " diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 2a311bf..0377555 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -103,11 +103,11 @@ sandbox_receive_and_parse_client_request(struct sandbox *sandbox) libuv_callbacks_on_allocate_setup_request_response_data, libuv_callbacks_on_read_parse_http_request); worker_thread_process_io(); - if (sandbox->request_response_data_length == 0) { - perror("request_response_data_length was unexpectedly 0"); - return 0 - }; #endif + if (sandbox->request_response_data_length == 0) { + debuglog("request_response_data_length was unexpectedly 0"); + return 0; + } sandbox->request_length = sandbox->request_response_data_length; return 1; } @@ -343,6 +343,9 @@ done: err: fprintf(stderr, "%s", error_message); assert(sandbox->state == SANDBOX_RUNNING); + send(sandbox->client_socket_descriptor, HTTP_RESPONSE_400_BAD_REQUEST, strlen(HTTP_RESPONSE_400_BAD_REQUEST), + 0); + software_interrupt_disable(); sandbox_set_as_error(sandbox, SANDBOX_RUNNING); goto done; }