Skip to content

Commit 89b3237

Browse files
committed
src: forbid reset_handler for SIGSEGV handling
This is not easily implementable, and should be explicitly disallowed. PR-URL: #27775 Refs: #27246 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent e256204 commit 89b3237

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/node.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,15 @@ void LoadEnvironment(Environment* env) {
477477
USE(StartMainThreadExecution(env));
478478
}
479479

480+
#ifdef __POSIX__
481+
typedef void (*sigaction_cb)(int signo, siginfo_t* info, void* ucontext);
482+
#endif
480483
#if NODE_USE_V8_WASM_TRAP_HANDLER
481-
static std::atomic<void (*)(int signo, siginfo_t* info, void* ucontext)>
482-
previous_sigsegv_action;
484+
static std::atomic<sigaction_cb> previous_sigsegv_action;
483485

484486
void TrapWebAssemblyOrContinue(int signo, siginfo_t* info, void* ucontext) {
485487
if (!v8::TryHandleWebAssemblyTrapPosix(signo, info, ucontext)) {
486-
auto prev = previous_sigsegv_action.load();
488+
sigaction_cb prev = previous_sigsegv_action.load();
487489
if (prev != nullptr) {
488490
prev(signo, info, ucontext);
489491
} else {
@@ -502,13 +504,13 @@ void TrapWebAssemblyOrContinue(int signo, siginfo_t* info, void* ucontext) {
502504

503505
#ifdef __POSIX__
504506
void RegisterSignalHandler(int signal,
505-
void (*handler)(int signal,
506-
siginfo_t* info,
507-
void* ucontext),
507+
sigaction_cb handler,
508508
bool reset_handler) {
509+
CHECK_NOT_NULL(handler);
509510
#if NODE_USE_V8_WASM_TRAP_HANDLER
510511
if (signal == SIGSEGV) {
511512
CHECK(previous_sigsegv_action.is_lock_free());
513+
CHECK(!reset_handler);
512514
previous_sigsegv_action.store(handler);
513515
return;
514516
}

src/node.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,12 @@ class NODE_EXTERN AsyncResource {
815815
};
816816

817817
#ifndef _WIN32
818-
// Register a signal handler without interrupting
819-
// any handlers that node itself needs.
818+
// Register a signal handler without interrupting any handlers that node
819+
// itself needs. This does override handlers registered through
820+
// process.on('SIG...', function() { ... }). The `reset_handler` flag indicates
821+
// whether the signal handler for the given signal should be reset to its
822+
// default value before executing the handler (i.e. it works like SA_RESETHAND).
823+
// The `reset_handler` flag is invalid when `signal` is SIGSEGV.
820824
NODE_EXTERN
821825
void RegisterSignalHandler(int signal,
822826
void (*handler)(int signal,

0 commit comments

Comments
 (0)