From 919a3bae1c5f2024b09e127a15c752d9dc0aa9a6 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Thu, 8 Feb 2024 00:29:53 +0100 Subject: [PATCH] http: protect against zero-length chunks A zero-length chunk marks the end of the body, so prevent any from possibly occurring in the middle of the body. --- lib/std/http/Client.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig index 2c45b36173..ed6aec55aa 100644 --- a/lib/std/http/Client.zig +++ b/lib/std/http/Client.zig @@ -1018,9 +1018,11 @@ pub const Request = struct { pub fn write(req: *Request, bytes: []const u8) WriteError!usize { switch (req.transfer_encoding) { .chunked => { - try req.connection.?.writer().print("{x}\r\n", .{bytes.len}); - try req.connection.?.writer().writeAll(bytes); - try req.connection.?.writer().writeAll("\r\n"); + if (bytes.len > 0) { + try req.connection.?.writer().print("{x}\r\n", .{bytes.len}); + try req.connection.?.writer().writeAll(bytes); + try req.connection.?.writer().writeAll("\r\n"); + } return bytes.len; },