From 2bee3d552e085ee1388c709df83b355c40c5dbf6 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 17 Jan 2024 09:58:16 +0200 Subject: [PATCH 1/2] Fix use-after-free Fixes #443 --- src/external_copy/string.cc | 6 ++++-- src/isolate/executor.cc | 5 +++++ src/isolate/executor.h | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/external_copy/string.cc b/src/external_copy/string.cc index 8c6c4400..a6f65269 100644 --- a/src/external_copy/string.cc +++ b/src/external_copy/string.cc @@ -20,7 +20,8 @@ class ExternalString final : public v8::String::ExternalStringResource { ExternalString(const ExternalString&) = delete; ~ExternalString() final { - IsolateEnvironment::GetCurrent()->AdjustExtraAllocatedMemory(-static_cast(this->value->size())); + if (auto *env = IsolateEnvironment::GetCurrent()) + env->AdjustExtraAllocatedMemory(-static_cast(this->value->size())); } auto operator= (const ExternalString&) = delete; @@ -46,7 +47,8 @@ class ExternalStringOneByte final : public v8::String::ExternalOneByteStringReso ExternalStringOneByte(const ExternalStringOneByte&) = delete; ~ExternalStringOneByte() final { - IsolateEnvironment::GetCurrent()->AdjustExtraAllocatedMemory(-static_cast(this->value->size())); + if (auto *env = IsolateEnvironment::GetCurrent()) + env->AdjustExtraAllocatedMemory(-static_cast(this->value->size())); } auto operator= (const ExternalStringOneByte&) = delete; diff --git a/src/isolate/executor.cc b/src/isolate/executor.cc index 9c1e3e41..57cb8555 100644 --- a/src/isolate/executor.cc +++ b/src/isolate/executor.cc @@ -17,6 +17,11 @@ Executor::Executor(IsolateEnvironment& env) : default_executor{*(current_executor == nullptr ? (current_executor = this) : ¤t_executor->default_executor)}, default_thread{&default_executor == this ? std::this_thread::get_id() : default_executor.default_thread} {} +Executor::~Executor() { + if (current_executor == this) + current_executor = nullptr; +} + auto Executor::MayRunInlineTasks(IsolateEnvironment& env) -> bool { if (current_executor == &env.executor) { if (env.nodejs_isolate) { diff --git a/src/isolate/executor.h b/src/isolate/executor.h index b4a149e6..529c5f3b 100644 --- a/src/isolate/executor.h +++ b/src/isolate/executor.h @@ -21,7 +21,7 @@ class Executor { // "En taro adun" public: explicit Executor(IsolateEnvironment& env); Executor(const Executor&) = delete; - ~Executor() = default; + ~Executor(); auto operator= (const Executor&) = delete; static auto GetCurrentEnvironment() -> IsolateEnvironment*; From 8401dddb67b6da23e3d560c03a8d875bf93780f3 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 17 Jan 2024 09:48:35 +0200 Subject: [PATCH 2/2] CI: Update actions and fix prebuild on osx --- .github/workflows/build.yml | 6 +++--- .github/workflows/prebuild.yml | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 86b9cee4..8233b9af 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: # https://github.com/nodejs/node-gyp/issues/2869 - run: python3 -m pip install setuptools - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Add msbuild to PATH @@ -33,7 +33,7 @@ jobs: with: max_attempts: 3 retry_on: error - timeout_seconds: 240 + timeout_minutes: 6 command: | npm test @@ -44,7 +44,7 @@ jobs: node-version: [ 16, 18, 20 ] container: node:${{ matrix.node-version }}-alpine steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: install build deps run: | apk add g++ make python3 diff --git a/.github/workflows/prebuild.yml b/.github/workflows/prebuild.yml index f9b43980..1d69c4ac 100644 --- a/.github/workflows/prebuild.yml +++ b/.github/workflows/prebuild.yml @@ -13,9 +13,11 @@ jobs: os: [ubuntu-20.04, macos-latest, windows-latest] fail-fast: false steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + # https://github.com/nodejs/node-gyp/issues/2869 + - run: python3 -m pip install setuptools - name: Use Node.js 18.x - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18.x - name: Add msbuild to PATH @@ -39,9 +41,9 @@ jobs: prebuild-alpine: runs-on: ubuntu-latest - container: node:18-alpine3.18 + container: node:18-alpine3.19 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: install build deps run: | apk add g++ make python3