Skip to content

Commit

Permalink
More checks against null-dereferences
Browse files Browse the repository at this point in the history
Summary: Check against failed allocations.

Reviewed By: neildhar

Differential Revision: D55862812

fbshipit-source-id: 07bddb45e605d660f2dcc4c0e797419a111e3320
  • Loading branch information
werew authored and facebook-github-bot committed Apr 20, 2024
1 parent 30a9eb6 commit b668a73
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions API/hermes_sandbox/HermesSandboxRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,10 @@ class HermesSandboxRuntimeImpl : public facebook::hermes::HermesSandboxRuntime,
sb::Ptr<GrowableBufferImpl> self{mod, buf};
if (sz < self->size)
return;
u32 newData = w2c_hermes_realloc(mod, self->data, sz);
self->data = newData;
self->size = sz;
if (u32 newData = w2c_hermes_realloc(mod, self->data, sz)) {
self->data = newData;
self->size = sz;
}
}

/// Copy the contents of this GrowableBuffer into an std::string and return
Expand Down Expand Up @@ -1214,6 +1215,9 @@ class HermesSandboxRuntimeImpl : public facebook::hermes::HermesSandboxRuntime,
auto alloc = w2c_hermes_malloc(
&runtime,
sizeof(PropNameIDListWrapper) + sizeof(SandboxPropNameID) * sz);
if (!alloc) {
abort();
}

sb::Ptr<PropNameIDListWrapper> self(&runtime, alloc);
self->vtable = runtime.propNameIDListVTable_;
Expand Down

0 comments on commit b668a73

Please sign in to comment.