commit 4a5f915

Santtu Lakkala  ·  2026-05-22 08:08:56 +0000 UTC
parent 6c1c0ef
Fix error body leaks

activitypub_post_handler uses custom error responses for 400 and 403.
The 400 NULL check was reversed and 403 was missing the check in
httpd_connection and both errors were lost and leaked.

Add a common custom error gate around all default errors to avoid
similar issues in the future.
1 files changed,  +10, -8
+10, -8
 1@@ -600,17 +600,19 @@ void httpd_connection(FILE *f)
 2         status = HTTP_STATUS_NOT_FOUND;
 3     }
 4 
 5-    if (status == HTTP_STATUS_FORBIDDEN)
 6-        body = xs_str_new("<h1>403 Forbidden (" USER_AGENT ")</h1>");
 7+    if (body == NULL) {
 8+        if (status == HTTP_STATUS_FORBIDDEN)
 9+            body = xs_str_new("<h1>403 Forbidden (" USER_AGENT ")</h1>");
10 
11-    if (status == HTTP_STATUS_NOT_FOUND)
12-        body = xs_str_new("<h1>404 Not Found (" USER_AGENT ")</h1>");
13+        if (status == HTTP_STATUS_NOT_FOUND)
14+            body = xs_str_new("<h1>404 Not Found (" USER_AGENT ")</h1>");
15 
16-    if (status == HTTP_STATUS_GONE)
17-        body = xs_str_new("<h1>410 Gone (" USER_AGENT ")</h1>");
18+        if (status == HTTP_STATUS_GONE)
19+            body = xs_str_new("<h1>410 Gone (" USER_AGENT ")</h1>");
20 
21-    if (status == HTTP_STATUS_BAD_REQUEST && body != NULL)
22-        body = xs_str_new("<h1>400 Bad Request (" USER_AGENT ")</h1>");
23+        if (status == HTTP_STATUS_BAD_REQUEST)
24+            body = xs_str_new("<h1>400 Bad Request (" USER_AGENT ")</h1>");
25+    }
26 
27     if (status == HTTP_STATUS_SEE_OTHER)
28         headers = xs_dict_append(headers, "location", body);