Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
[cli] Fix the UAF with by-value receivers and --weak-refs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhenrymantilla committed Feb 5, 2021
1 parent 69546a2 commit 785389d
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 @@ -846,10 +846,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 785389d

Please sign in to comment.