summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--hittpd.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/hittpd.c b/hittpd.c
index 13306fe..7ea8592 100644
--- a/hittpd.c
+++ b/hittpd.c
@@ -299,11 +299,22 @@ send_response(http_parser *p, int status, const char *msg,
 	    now,
 	    extra_headers);
 
-	if (!(status == 204 || status == 304))
+	if (len >= (int)sizeof buf) {
+		send_error(p, 413, "Payload Too Large");
+		return;
+	}
+
+	if (!(status == 204 || status == 304)) {
 		len += snprintf(buf + len, sizeof buf - len,
 		    "Content-Length: %jd\r\n",
 		    content_length(data));
 
+		if (len >= (int)sizeof buf) {
+			send_error(p, 413, "Payload Too Large");
+			return;
+		}
+	}
+
 	len += snprintf(buf + len, sizeof buf - len,
 	    "\r\n"
 	    "%s",