Skip to content

Commit

Permalink
runtime: Validate pointer access instead of using coersion on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evaporei committed Sep 9, 2021
1 parent 821e337 commit a7bec0e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions runtime/test/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,11 @@ fn test_safe_null_ptr_read(api_version: Version) {
api_version,
);

let result_ptr: AscPtr<AscBigInt> = module.invoke_export0("safeNullPtrRead");
let result: BigInt = asc_get(&module, result_ptr).unwrap();
assert_eq!(result, BigInt::from(2));
module.invoke_export0_void("safeNullPtrRead");
}

#[tokio::test]
#[should_panic(expected = "Failed to sum BigInts because left hand side is 'null'")]
async fn safe_null_ptr_read_0_0_5() {
test_safe_null_ptr_read(API_VERSION_0_0_5);
}
13 changes: 6 additions & 7 deletions runtime/test/wasm_test/api_version_0_0_5/null_ptr_read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ class SafeBigInt extends Uint8Array {
}

@operator('+')
plus(other: SafeBigInt | null): SafeBigInt {
let x = this ? this : SafeBigInt.fromI32(0);
let y = other ? other : SafeBigInt.fromI32(0);
plus(other: SafeBigInt): SafeBigInt {
assert(this != null, "Failed to sum BigInts because left hand side is 'null'");

return changetype<SafeBigInt>(bigInt.plus(changetype<BigInt>(x), changetype<BigInt>(y)));
return changetype<SafeBigInt>(bigInt.plus(changetype<BigInt>(this), changetype<BigInt>(other)));
}
}

Expand All @@ -71,13 +70,13 @@ class Wrapper2 {
) {}
}

export function safeNullPtrRead(): SafeBigInt {
export function safeNullPtrRead(): void {
let x = SafeBigInt.fromI32(2);
let y: SafeBigInt | null = null;

let wrapper2 = new Wrapper2(y);

// Breaks as well, but by our assertion, before getting into
// the Rust code.
wrapper2.n = wrapper2.n + x;

return wrapper2.n!;
}
Binary file modified runtime/test/wasm_test/api_version_0_0_5/null_ptr_read.wasm
Binary file not shown.

0 comments on commit a7bec0e

Please sign in to comment.