Commit a92cba8c authored by Maya Lekova's avatar Maya Lekova Committed by V8 LUCI CQ

[fastcall] Fix internal OOB in FastCAPI.fast_call_count

The fast_call_count getter in d8 was not properly initialised as
throwing when called as a constructor. As a result, it was possible
to pass a new object as its `this` and then attempt to "unwrap" it,
resulting in reading OOB in the new object. This CL also strenghtens
slow_call_count and reset_counts and adds a regression test.

Bug: chromium:1241464
Change-Id: I9b6e9a4e38a974dc111a53b911c73514c30de9df
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3110369Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76426}
parent 0179f6a6
......@@ -631,16 +631,19 @@ Local<FunctionTemplate> Shell::CreateTestFastCApiTemplate(Isolate* isolate) {
SideEffectType::kHasSideEffect, &is_valid_api_object_c_func));
api_obj_ctor->PrototypeTemplate()->Set(
isolate, "fast_call_count",
FunctionTemplate::New(isolate, FastCApiObject::FastCallCount,
Local<Value>(), signature));
FunctionTemplate::New(
isolate, FastCApiObject::FastCallCount, Local<Value>(), signature,
1, ConstructorBehavior::kThrow, SideEffectType::kHasNoSideEffect));
api_obj_ctor->PrototypeTemplate()->Set(
isolate, "slow_call_count",
FunctionTemplate::New(isolate, FastCApiObject::SlowCallCount,
Local<Value>(), signature));
FunctionTemplate::New(
isolate, FastCApiObject::SlowCallCount, Local<Value>(), signature,
1, ConstructorBehavior::kThrow, SideEffectType::kHasNoSideEffect));
api_obj_ctor->PrototypeTemplate()->Set(
isolate, "reset_counts",
FunctionTemplate::New(isolate, FastCApiObject::ResetCounts,
Local<Value>(), signature));
Local<Value>(), signature, 1,
ConstructorBehavior::kThrow));
}
api_obj_ctor->InstanceTemplate()->SetInternalFieldCount(
FastCApiObject::kV8WrapperObjectIndex + 1);
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --turbo-fast-api-calls
(function() {
const fast_c_api = new d8.test.FastCAPI();
const func1 = fast_c_api.fast_call_count;
assertThrows(() => new func1());
const func2 = fast_c_api.slow_call_count;
assertThrows(() => new func2());
const func3 = fast_c_api.reset_counts;
assertThrows(() => new func3());
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment