compiler: fix UAF when writing builtin.zig

This commit is contained in:
Andrew Kelley 2023-12-24 21:50:37 -07:00
parent 44e2dbe117
commit 4f8a44cd0f
2 changed files with 4 additions and 3 deletions

View file

@ -279,7 +279,8 @@ pub fn populateFile(comp: *Compilation, mod: *Module, file: *File) !void {
}
fn writeFile(file: *File, mod: *Module) !void {
var af = try mod.root.atomicFile(mod.root_src_path, .{ .make_path = true });
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var af = try mod.root.atomicFile(mod.root_src_path, .{ .make_path = true }, &buf);
defer af.deinit();
try af.file.writeAll(file.source);
try af.finish();

View file

@ -88,10 +88,10 @@ pub const Path = struct {
p: Path,
sub_path: []const u8,
options: fs.Dir.AtomicFileOptions,
buf: *[fs.MAX_PATH_BYTES]u8,
) !fs.AtomicFile {
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
break :p std.fmt.bufPrint(buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};