diff options
author | 2022-04-01 19:53:37 -0700 | |
---|---|---|
committer | 2022-04-01 19:53:37 -0700 | |
commit | c7727b136b8667328224357df0dbb0378fcf2e69 (patch) | |
tree | 6459fe216bb210ef3d74e217c990b7af53be28da | |
parent | 7a6b6639bcf6ee9c8c514a91201e56f5103fb2da (diff) | |
download | bun-c7727b136b8667328224357df0dbb0378fcf2e69.tar.gz bun-c7727b136b8667328224357df0dbb0378fcf2e69.tar.zst bun-c7727b136b8667328224357df0dbb0378fcf2e69.zip |
[bun.js] Fix use-after-free in Bun.write
Diffstat (limited to '')
-rw-r--r-- | src/javascript/jsc/webcore/response.zig | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig index a4c83fc43..639ee7f71 100644 --- a/src/javascript/jsc/webcore/response.zig +++ b/src/javascript/jsc/webcore/response.zig @@ -1963,7 +1963,6 @@ pub const Blob = struct { file_offset: u64, ) AsyncIO.WriteError!SizeType { var aio = &AsyncIO.global; - this.wrote = 0; aio.write( *WriteFile, this, @@ -2006,15 +2005,16 @@ pub const Blob = struct { return; } + const wrote = this.wrote; bun.default_allocator.destroy(this); - cb(cb_ctx, .{ .result = @truncate(SizeType, this.wrote) }); + cb(cb_ctx, .{ .result = @truncate(SizeType, wrote) }); } pub fn run(this: *WriteFile, task: *WriteFileTask) void { this.runAsyncFrame = async this.runAsync(task); } pub fn onWrite(this: *WriteFile, _: *HTTPClient.NetworkThread.Completion, result: AsyncIO.WriteError!usize) void { - this.wrote = @truncate(SizeType, result catch |err| { + this.wrote += @truncate(SizeType, result catch |err| { this.errno = err; this.wrote = 0; resume this.write_frame; |