aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-09-08 16:43:54 +0300
committerGitHub <noreply@github.com>2022-09-08 16:43:54 +0300
commit6a62a15ecde10300f6281e2d49fed34031d5f68a (patch)
treed0c5e7abd7ef2a1bc2b1d4ee283354f1da25322b /src/Module.zig
parenta7661f115dccf26b141557c923171f325cdc2757 (diff)
parentc7e45aebafef0372fe231816eeffd18198240f14 (diff)
downloadzig-6a62a15ecde10300f6281e2d49fed34031d5f68a.tar.gz
zig-6a62a15ecde10300f6281e2d49fed34031d5f68a.zip
Merge pull request #12773 from Vexu/stage2-fixes
Sema: fix UAF in zirClosureGet
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 3ae6c48edd..ea89225537 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -345,6 +345,15 @@ pub const CaptureScope = struct {
/// During sema, this map is backed by the gpa. Once sema completes,
/// it is reallocated using the value_arena.
captures: std.AutoHashMapUnmanaged(Zir.Inst.Index, TypedValue) = .{},
+
+ pub fn failed(noalias self: *const @This()) bool {
+ return self.captures.available == 0 and self.captures.size == std.math.maxInt(u32);
+ }
+
+ pub fn fail(noalias self: *@This()) void {
+ self.captures.available = 0;
+ self.captures.size = std.math.maxInt(u32);
+ }
};
pub const WipCaptureScope = struct {
@@ -383,6 +392,7 @@ pub const WipCaptureScope = struct {
pub fn deinit(noalias self: *@This()) void {
if (!self.finalized) {
self.scope.captures.deinit(self.gpa);
+ self.scope.fail();
}
self.* = undefined;
}