improved robustness of client/server encoding functions
[rocksndiamonds.git] / src / libgame / http.c
index 592aeb17c0a4220a7688527a0a01293ae92e93b5..b494ac42bd9d57d04bf84f14ed3d6189ef35c305 100644 (file)
@@ -37,7 +37,9 @@ void ConvertHttpRequestBodyToServerEncoding(struct HttpRequest *request)
 {
   char *body_utf8 = getUTF8FromLatin1(request->body);
 
-  strcpy(request->body, body_utf8);
+  strncpy(request->body, body_utf8, MAX_HTTP_BODY_SIZE);
+  request->body[MAX_HTTP_BODY_SIZE] = '\0';
+
   checked_free(body_utf8);
 }
 
@@ -45,10 +47,12 @@ void ConvertHttpResponseBodyToClientEncoding(struct HttpResponse *response)
 {
   char *body_latin1 = getLatin1FromUTF8(response->body);
 
-  strcpy(response->body, body_latin1);
-  checked_free(body_latin1);
+  strncpy(response->body, body_latin1, MAX_HTTP_BODY_SIZE);
+  response->body[MAX_HTTP_BODY_SIZE] = '\0';
 
   response->body_size = strlen(response->body);
+
+  checked_free(body_latin1);
 }
 
 static void SetHttpResponseToDefaults(struct HttpResponse *response)
@@ -290,7 +294,7 @@ boolean DoHttpRequest(struct HttpRequest *request,
   checked_free(send_buffer);
   checked_free(recv_buffer);
 
-  runtime.api_server = success;
+  runtime.use_api_server = success;
 
   return success;
 }