From b47bd031ca0b8c3a14c0dd6537e13e60779471a4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 11 Feb 2024 17:38:28 -0700 Subject: [PATCH] std.http.Server: protect against zero-length chunks companion commit to 919a3bae1c5f2024b09e127a15c752d9dc0aa9a6 --- lib/std/http/Server.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/std/http/Server.zig b/lib/std/http/Server.zig index 8447c4e03e..693247e730 100644 --- a/lib/std/http/Server.zig +++ b/lib/std/http/Server.zig @@ -693,9 +693,11 @@ pub const Response = struct { switch (res.transfer_encoding) { .chunked => { - try res.connection.writer().print("{x}\r\n", .{bytes.len}); - try res.connection.writeAll(bytes); - try res.connection.writeAll("\r\n"); + if (bytes.len > 0) { + try res.connection.writer().print("{x}\r\n", .{bytes.len}); + try res.connection.writeAll(bytes); + try res.connection.writeAll("\r\n"); + } return bytes.len; },