Skip to content

Commit

Permalink
[cli] Fix the UAF with by-value receivers and --weak-refs (#2448)
Browse files Browse the repository at this point in the history
Fixes #2447
  • Loading branch information
danielhenrymantilla authored Feb 5, 2021
1 parent de2a5d7 commit 03c692e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 4 additions & 5 deletions crates/cli-support/src/js/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,14 @@ impl<'a, 'b> Builder<'a, 'b> {
drop(params.next());
if js.cx.config.debug {
js.prelude(
"if (this.ptr == 0) throw new Error('Attempt to use a moved value');\n",
"if (this.ptr == 0) throw new Error('Attempt to use a moved value');",
);
}
if consumes_self {
js.prelude("var ptr = this.ptr;");
js.prelude("this.ptr = 0;");
js.args.push("ptr".to_string());
js.prelude("const ptr = this.__destroy_into_raw();");
js.args.push("ptr".into());
} else {
js.args.push("this.ptr".to_string());
js.args.push("this.ptr".into());
}
}
None => {}
Expand Down
7 changes: 6 additions & 1 deletion crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,15 @@ impl<'a> Context<'a> {

dst.push_str(&format!(
"
free() {{
__destroy_into_raw() {{
const ptr = this.ptr;
this.ptr = 0;
{}
return ptr;
}}
free() {{
const ptr = this.__destroy_into_raw();
wasm.{}(ptr);
}}
",
Expand Down

0 comments on commit 03c692e

Please sign in to comment.