zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 4f8a44cd0f636f3ffe008b2cedafa1e51a4a3796 (tree)
parent 44e2dbe117fe79b99a970990878a061bdd26ff55
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun, 24 Dec 2023 21:50:37 -0700

compiler: fix UAF when writing builtin.zig

Diffstat:
Msrc/Builtin.zig | 3++-
Msrc/Package.zig | 4++--
2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/Builtin.zig b/src/Builtin.zig @@ -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(); diff --git a/src/Package.zig b/src/Package.zig @@ -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; };