added allocating memory buffers that are too large for the stack
authorHolger Schemel <info@artsoft.org>
Sat, 1 May 2021 15:12:15 +0000 (17:12 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 1 May 2021 15:12:35 +0000 (17:12 +0200)
src/libgame/http.c

index 74fafb379713e61b5d4d7a9edf768da73090a896..30f4c03a572aa7be5e4d043b31df6c4b4f592690 100644 (file)
@@ -146,8 +146,11 @@ static boolean SetHTTPResponseBody(struct HttpResponse *response, char *buffer,
   return TRUE;
 }
 
-boolean DoHttpRequest(struct HttpRequest *request,
-                     struct HttpResponse *response)
+static boolean DoHttpRequestExt(struct HttpRequest *request,
+                               struct HttpResponse *response,
+                               char *send_buffer,
+                               char *recv_buffer,
+                               int max_http_buffer_size)
 {
   SDLNet_SocketSet socket_set;
   TCPsocket socket;
@@ -213,10 +216,6 @@ boolean DoHttpRequest(struct HttpRequest *request,
           request->hostname,
           (int)strlen(request->body));
 
-  int max_http_buffer_size = MAX_HTTP_HEAD_SIZE + MAX_HTTP_BODY_SIZE;
-  char send_buffer[max_http_buffer_size + 1];
-  char recv_buffer[max_http_buffer_size + 1];
-
   snprintf(send_buffer, max_http_buffer_size,
           "%s\r\n%s", request->head, request->body);
 
@@ -276,3 +275,20 @@ boolean DoHttpRequest(struct HttpRequest *request,
 
   return TRUE;
 }
+
+boolean DoHttpRequest(struct HttpRequest *request,
+                     struct HttpResponse *response)
+{
+  int max_http_buffer_size = MAX_HTTP_HEAD_SIZE + MAX_HTTP_BODY_SIZE;
+  char *send_buffer = checked_malloc(max_http_buffer_size + 1);
+  char *recv_buffer = checked_malloc(max_http_buffer_size + 1);
+
+  boolean success = DoHttpRequestExt(request, response,
+                                    send_buffer, recv_buffer,
+                                    max_http_buffer_size);
+
+  checked_free(send_buffer);
+  checked_free(recv_buffer);
+
+  return success;
+}