authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-24 21:50:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:21-07:00
log4f8a44cd0f636f3ffe008b2cedafa1e51a4a3796
treee395558fb0348b842e20de3a059da10673bf3bbd
parent44e2dbe117fe79b99a970990878a061bdd26ff55

compiler: fix UAF when writing builtin.zig


2 files changed, 4 insertions(+), 3 deletions(-)

src/Builtin.zig+2-1
......@@ -279,7 +279,8 @@ pub fn populateFile(comp: *Compilation, mod: *Module, file: *File) !void {
279279}
280280
281281fn writeFile(file: *File, mod: *Module) !void {
282 var af = try mod.root.atomicFile(mod.root_src_path, .{ .make_path = true });
282 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
283 var af = try mod.root.atomicFile(mod.root_src_path, .{ .make_path = true }, &buf);
283284 defer af.deinit();
284285 try af.file.writeAll(file.source);
285286 try af.finish();
src/Package.zig+2-2
......@@ -88,10 +88,10 @@ pub const Path = struct {
8888 p: Path,
8989 sub_path: []const u8,
9090 options: fs.Dir.AtomicFileOptions,
91 buf: *[fs.MAX_PATH_BYTES]u8,
9192 ) !fs.AtomicFile {
92 var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
9393 const joined_path = if (p.sub_path.len == 0) sub_path else p: {
94 break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
94 break :p std.fmt.bufPrint(buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
9595 p.sub_path, sub_path,
9696 }) catch return error.NameTooLong;
9797 };