Skip to content

Commit 919a3ba

Browse files
jacobly0andrewrk
authored andcommitted
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 parent 3122fd0 commit 919a3ba

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/std/http/Client.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
},

0 commit comments

Comments
 (0)