Skip to content

Commit 311b84c

Browse files
Jake ChampionJakeChampion
authored andcommitted
fix: ensure retrieving the property definitions of ObjectStoreEntry.prototype.body and ObjectStoreEntry.bodyUsed do not cause panics by ensuring we have a valid entry in their Slots
1 parent 62476f5 commit 311b84c

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

c-dependencies/js-compute-runtime/builtins/object-store.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ bool bodyAll(JSContext *cx, unsigned argc, JS::Value *vp) {
5252

5353
bool body_get(JSContext *cx, unsigned argc, JS::Value *vp) {
5454
METHOD_HEADER(0)
55+
if (!JS::GetReservedSlot(self, Slots::HasBody).isBoolean()) {
56+
JS::SetReservedSlot(self, Slots::HasBody, JS::BooleanValue(false));
57+
}
5558
return RequestOrResponse::body_get(cx, args, self, true);
5659
}
5760

5861
bool bodyUsed_get(JSContext *cx, unsigned argc, JS::Value *vp) {
5962
METHOD_HEADER(0)
63+
if (!JS::GetReservedSlot(self, Slots::BodyUsed).isBoolean()) {
64+
JS::SetReservedSlot(self, Slots::BodyUsed, JS::BooleanValue(false));
65+
}
6066
args.rval().setBoolean(RequestOrResponse::body_used(self));
6167
return true;
6268
}
@@ -85,7 +91,7 @@ JSObject *create(JSContext *cx, fastly_body_handle_t body_handle) {
8591

8692
JS::SetReservedSlot(objectStoreEntry, Slots::Body, JS::Int32Value(body_handle));
8793
JS::SetReservedSlot(objectStoreEntry, Slots::BodyStream, JS::NullValue());
88-
JS::SetReservedSlot(objectStoreEntry, Slots::HasBody, JS::TrueValue());
94+
JS::SetReservedSlot(objectStoreEntry, Slots::HasBody, JS::BooleanValue(true));
8995
JS::SetReservedSlot(objectStoreEntry, Slots::BodyUsed, JS::FalseValue());
9096

9197
return objectStoreEntry;

c-dependencies/js-compute-runtime/builtins/object-store.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace ObjectStoreEntry {
66
// Register the class.
77
bool init_class(JSContext *cx, JS::HandleObject global);
8+
bool is_instance(JSObject *obj);
9+
bool is_instance(JS::Value val);
810
} // namespace ObjectStoreEntry
911

1012
namespace ObjectStore {

c-dependencies/js-compute-runtime/js-compute-builtins.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,10 @@ bool is_instance(JSObject *obj);
427427
}
428428

429429
namespace RequestOrResponse {
430-
bool is_instance(JSObject *obj) { return Request::is_instance(obj) || Response::is_instance(obj); }
430+
bool is_instance(JSObject *obj) {
431+
return Request::is_instance(obj) || Response::is_instance(obj) ||
432+
ObjectStoreEntry::is_instance(obj);
433+
}
431434

432435
uint32_t handle(JSObject *obj) {
433436
MOZ_ASSERT(is_instance(obj));

integration-tests/js-compute/fixtures/object-store/fastly.toml.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ service_id = ""
1313

1414
[local_server]
1515
[local_server.object_store]
16-
example-test-object-store = []
16+
17+
[[local_server.object_store.example-test-object-store]]
18+
key = "placeholder"
19+
data = 'placholder'
1720

1821
[local_server.backends]
1922

0 commit comments

Comments
 (0)