std.http.Client: fix UAF when handling redirects

closes #19071
This commit is contained in:
Andrew Kelley
2024-02-25 15:14:28 -07:00
parent 723d13f831
commit 032c2ee9bc
2 changed files with 79 additions and 2 deletions

View File

@@ -857,9 +857,12 @@ pub const Request = struct {
/// Must be called after `send` and, if any data was written to the request
/// body, then also after `finish`.
pub fn wait(req: *Request) WaitError!void {
const connection = req.connection.?;
while (true) {
// This while loop is for handling redirects, which means the request's
// connection may be different than the previous iteration. However, it
// is still guaranteed to be non-null with each iteration of this loop.
const connection = req.connection.?;
while (true) { // handle redirects
while (true) { // read headers
try connection.fill();