mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
compiler: fix UAF when writing builtin.zig
This commit is contained in:
parent
44e2dbe117
commit
4f8a44cd0f
2 changed files with 4 additions and 3 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue