Commit 9dc25dd0b6

Andrew Kelley <andrew@ziglang.org>
2021-12-31 07:14:34
stage2: fix UAF of system_libs
1 parent 55243cf
Changed files (2)
src/Compilation.zig
@@ -1985,7 +1985,7 @@ pub fn update(comp: *Compilation) !void {
 
         // This resets the link.File to operate as if we called openPath() in create()
         // instead of simulating -fno-emit-bin.
-        var options = comp.bin_file.options;
+        var options = comp.bin_file.options.move();
         if (comp.whole_bin_sub_path) |sub_path| {
             options.emit = .{
                 .directory = tmp_artifact_directory.?,
src/link.zig
@@ -167,6 +167,12 @@ pub const Options = struct {
     pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode {
         return if (options.use_lld) .Obj else options.output_mode;
     }
+
+    pub fn move(self: *Options) Options {
+        const copied_state = self.*;
+        self.system_libs = .{};
+        return copied_state;
+    }
 };
 
 pub const File = struct {