authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-03 22:07:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-03 22:07:21-07:00
log0c598100d8dbcf94fa8916a8aa5dcf5f55ef6d46
treee440e716ca89030384cf7cb43ce0a279224534d8
parentedfede575c3113c3611b14a868e8d1e956ca9ef5

stage2: fix use-after-free of export symbol name


1 files changed, 7 insertions(+), 3 deletions(-)

src-self-hosted/Module.zig+7-3
......@@ -1673,6 +1673,7 @@ fn deleteDeclExports(self: *Module, decl: *Decl) void {
16731673 entry.value.destroy(self.gpa);
16741674 }
16751675 _ = self.symbol_exports.remove(exp.options.name);
1676 self.gpa.free(exp.options.name);
16761677 self.gpa.destroy(exp);
16771678 }
16781679 self.gpa.free(kv.value);
......@@ -1773,7 +1774,7 @@ pub fn resolveDefinedValue(self: *Module, scope: *Scope, base: *Inst) !?Value {
17731774 return null;
17741775}
17751776
1776pub fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const u8, exported_decl: *Decl) !void {
1777pub fn analyzeExport(self: *Module, scope: *Scope, src: usize, borrowed_symbol_name: []const u8, exported_decl: *Decl) !void {
17771778 try self.ensureDeclAnalyzed(exported_decl);
17781779 const typed_value = exported_decl.typed_value.most_recent.typed_value;
17791780 switch (typed_value.ty.zigTypeTag()) {
......@@ -1787,6 +1788,9 @@ pub fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []co
17871788 const new_export = try self.gpa.create(Export);
17881789 errdefer self.gpa.destroy(new_export);
17891790
1791 const symbol_name = try self.gpa.dupe(u8, borrowed_symbol_name);
1792 errdefer self.gpa.free(symbol_name);
1793
17901794 const owner_decl = scope.decl().?;
17911795
17921796 new_export.* = .{
......@@ -1799,7 +1803,7 @@ pub fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []co
17991803 };
18001804
18011805 // Add to export_owners table.
1802 const eo_gop = self.export_owners.getOrPut(self.gpa, owner_decl) catch unreachable;
1806 const eo_gop = self.export_owners.getOrPutAssumeCapacity(owner_decl);
18031807 if (!eo_gop.found_existing) {
18041808 eo_gop.entry.value = &[0]*Export{};
18051809 }
......@@ -1808,7 +1812,7 @@ pub fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []co
18081812 errdefer eo_gop.entry.value = self.gpa.shrink(eo_gop.entry.value, eo_gop.entry.value.len - 1);
18091813
18101814 // Add to exported_decl table.
1811 const de_gop = self.decl_exports.getOrPut(self.gpa, exported_decl) catch unreachable;
1815 const de_gop = self.decl_exports.getOrPutAssumeCapacity(exported_decl);
18121816 if (!de_gop.found_existing) {
18131817 de_gop.entry.value = &[0]*Export{};
18141818 }