Skip to content

Commit 8671166

Browse files
committed
[clang-tidy] Fix bugprone-bad-signal-to-kill-thread crash when SIGTERM was undefined after definition.
`PP->getMacroInfo()` returns nullptr for undefined macro, which leads to null-dereference at `MI->tockens().back()`. Stack dump: ``` #0 0x000000000217d15a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x217d15a) #1 0x000000000217b17c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x217b17c) #2 0x000000000217b2e3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x217b2e3) #3 0x00007f39be5b1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #4 0x0000000000593532 clang::tidy::bugprone::BadSignalToKillThreadCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x593532) ``` Reviewed By: hokein Differential Revision: https://reviews.llvm.org/D85401
1 parent 504a197 commit 8671166

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ static Preprocessor *PP;
3030

3131
void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
3232
const auto IsSigterm = [](const auto &KeyValue) -> bool {
33-
return KeyValue.first->getName() == "SIGTERM";
33+
return KeyValue.first->getName() == "SIGTERM" &&
34+
KeyValue.first->hasMacroDefinition();
3435
};
3536
const auto TryExpandAsInteger =
3637
[](Preprocessor::macro_iterator It) -> Optional<unsigned> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: clang-tidy %s --checks=-*,bugprone-bad-signal-to-kill-thread -- | count 0
2+
3+
#define SIGTERM 15
4+
#undef SIGTERM // no-crash
5+
using pthread_t = int;
6+
int pthread_kill(pthread_t thread, int sig);
7+
8+
int func() {
9+
pthread_t thread;
10+
return pthread_kill(thread, 0);
11+
}

0 commit comments

Comments
 (0)