authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-08 00:29:53+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-08 01:29:49-08:00
log919a3bae1c5f2024b09e127a15c752d9dc0aa9a6
treeb190c28e05805f8dce5bfe4680d04b03929e1211
parent3122fd0ba0eb4cdb17616658b462a255a37f1ad7

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.

1 files changed, 5 insertions(+), 3 deletions(-)

lib/std/http/Client.zig+5-3
......@@ -1018,9 +1018,11 @@ pub const Request = struct {
10181018 pub fn write(req: *Request, bytes: []const u8) WriteError!usize {
10191019 switch (req.transfer_encoding) {
10201020 .chunked => {
1021 try req.connection.?.writer().print("{x}\r\n", .{bytes.len});
1022 try req.connection.?.writer().writeAll(bytes);
1023 try req.connection.?.writer().writeAll("\r\n");
1021 if (bytes.len > 0) {
1022 try req.connection.?.writer().print("{x}\r\n", .{bytes.len});
1023 try req.connection.?.writer().writeAll(bytes);
1024 try req.connection.?.writer().writeAll("\r\n");
1025 }
10241026
10251027 return bytes.len;
10261028 },