Sema: fix UAF in zirClosureGet

Previously if a decl failed its capture scope would be deallocated and
set to undefined which would then lead to invalid dereference in
`zirClosureGet`. To avoid this set the capture scope to a special
failed state and fail the current decl with dependency failure if
the failed state is encountered in `zirClosureGet`.

Closes #12433
Closes #12530
Closes #12593
This commit is contained in:
Veikka Tuominen
2022-09-07 22:05:01 +03:00
parent 37afab2add
commit 99826a2ba8
4 changed files with 70 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
pub inline fn instanceRequestAdapter() void {}
pub inline fn requestAdapter(
comptime callbackArg: fn () callconv(.Inline) void,
) void {
_ = (struct {
pub fn callback() callconv(.C) void {
callbackArg();
}
}).callback;
instanceRequestAdapter(undefined); // note wrong number of arguments here
}
inline fn foo() void {}
pub export fn entry() void {
requestAdapter(foo);
}
// error
// backend=stage2
// target=native
//
// :11:5: error: expected 0 argument(s), found 1
// :1:12: note: function declared here
// :17:19: note: called from here

View File

@@ -0,0 +1,24 @@
fn Observable(comptime T: type) type {
return struct {
fn map(Src: T, Dst: anytype, function: fn (T) Dst) Dst {
_ = Src;
_ = function;
return Observable(Dst);
}
};
}
fn u32Tou64(x: u32) u64 {
_ = x;
return 0;
}
pub export fn entry() void {
Observable(u32).map(u32, u64, u32Tou64(0));
}
// error
// backend=stage2
// target=native
//
// :17:25: error: expected type 'u32', found 'type'