Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGINT handler throws uncaught exception and might have UB #404

Open
mo-xiaoming opened this issue Jun 6, 2021 · 1 comment
Open

SIGINT handler throws uncaught exception and might have UB #404

mo-xiaoming opened this issue Jun 6, 2021 · 1 comment

Comments

@mo-xiaoming
Copy link
Contributor

Setup

OS: macOS catalina
LLVM: brew installed llvm: stable 12.0.0
Compiler: Apple clang version 12.0.0 (clang-1200.0.31.1)
readline: brew installed readline: stable 8.1

hobbes was built with LLVM_DIR=/usr/local/Cellar/llvm/12.0.0_1/lib/cmake

Uncaught exception

$ ./hi
hi : an interactive shell for hobbes
      type ':h' for help on commands

> 3 + 5
8
> ^C libc++abi: terminating with uncaught exception of type hi::interruption_error: std::exception
Abort trap: 6

UB

Might be unrelated to the above problem, but the SIGINT handler might have some issues

[[noreturn]] void interruptEval(int) {
  siglongjmp(continueInterrupt, 42);
}

Although siglongjmp family can be used in C signal handling(reference), it is not among the list of C++ signal-safe functions(cppreference), which make it UB

siglongjmp jumps the execution to

void installInterruptHandler() {
  if (sigsetjmp(continueInterrupt,1) == 0) {
    signal(SIGINT, &interruptEval);
  } else if (!terminating) {
    throw interruption_error();
  } else {
    exit(-1);
  }
}

which throws interruption_error, and throwing in a signal handler is an UB as well

@smunix
Copy link
Contributor

smunix commented Jun 7, 2021

Agreed, throwing in a signal handler is an UB indeed. Do you mind pushing a pull request for review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants