diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-08-15 18:06:44 -0400 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-08-15 18:06:44 -0400 |
| commit | bc42e791cf4b56f2854e87666e3295d8b167ad24 (patch) | |
| tree | fc371a9bc1268fe6d1b43f62e66a44a2546216fa /src/http.c | |
| parent | d3c9f9384fa3e743f48e1771a8519e3e4bb04ad6 (diff) | |
| download | beaker-bc42e791cf4b56f2854e87666e3295d8b167ad24.tar.gz | |
fix: harden socket I/O
Diffstat (limited to 'src/http.c')
| -rw-r--r-- | src/http.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -75,8 +75,8 @@ void send_status(const char *status_line) { "\r\n", status_line); - if (send(current_client_socket, http_response, strlen(http_response), 0) < - 0) { + if (beaker_send_all(current_client_socket, http_response, + strlen(http_response)) < 0) { beaker_log_errno_format("ERROR", "send_status: Failed to send HTTP status.\n"); } @@ -91,7 +91,7 @@ void send_response(const char *html) { } char http_response_header[BUFFER_SIZE * 2]; - int content_length = strlen(html); + size_t content_length = strlen(html); current_response_status = 200; current_response_size = content_length; char cookie_headers[BUFFER_SIZE]; @@ -101,20 +101,20 @@ void send_response(const char *html) { snprintf(http_response_header, sizeof(http_response_header), "HTTP/1.1 200 OK\r\n" "Content-Type: text/html; charset=UTF-8\r\n" - "Content-Length: %d\r\n" + "Content-Length: %zu\r\n" "%s" "Connection: close\r\n" "\r\n", content_length, cookie_headers); - if (send(current_client_socket, http_response_header, - strlen(http_response_header), 0) < 0) { + if (beaker_send_all(current_client_socket, http_response_header, + strlen(http_response_header)) < 0) { beaker_log_errno_format("ERROR", "send_response: Failed to send HTTP header.\n"); return; } - if (send(current_client_socket, html, content_length, 0) < 0) { + if (beaker_send_all(current_client_socket, html, content_length) < 0) { beaker_log_errno_format("ERROR", "send_response: Failed to send HTML body.\n"); return; @@ -146,8 +146,8 @@ void send_redirect(const char *location) { "\r\n", location, cookie_headers); - if (send(current_client_socket, http_response_header, - strlen(http_response_header), 0) < 0) { + if (beaker_send_all(current_client_socket, http_response_header, + strlen(http_response_header)) < 0) { beaker_log_errno_format("ERROR", "send_redirect: Failed to send redirect header.\n"); return; |
