-
Notifications
You must be signed in to change notification settings - Fork 15k
[ASan] Do not instrument catch block parameters on Windows #159618
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
Changes from 3 commits
ece2a2b
bff409d
043848d
2326be0
3497540
e4551b1
9b99935
04956f9
65f1741
fe312ec
a44a340
bd511b5
c5a0e78
992a650
0dec61a
112f078
2f544df
980e31d
7d93177
7fe17b5
98217a4
4b88967
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // RUN: %clangxx_asan %s -o %t | ||
davidmrdavid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // RUN: %run %t | FileCheck %s | ||
|
|
||
| // This test tests that declaring a parameter in a catch-block does not produce a false positive | ||
| // ASan error on Windows. | ||
|
|
||
| // This code is based on the repro in https://github.com/google/sanitizers/issues/749 | ||
| #include <cstdio> | ||
| #include <exception> | ||
|
|
||
| void throwInFunction() { throw std::exception("test2"); } | ||
|
|
||
| int main() { | ||
| // case 1: direct throw | ||
| try { | ||
| throw std::exception("test1"); | ||
| } catch (const std::exception &ex) { | ||
| puts(ex.what()); | ||
| // CHECK: test1 | ||
| } | ||
|
|
||
| // case 2: throw in function | ||
| try { | ||
| throwInFunction(); | ||
| } catch (const std::exception &ex) { | ||
| puts(ex.what()); | ||
| // CHECK: test2 | ||
| } | ||
|
|
||
| printf("Success!\n"); | ||
| // CHECK: Success! | ||
| return 0; | ||
| } | ||
davidmrdavid marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1397,6 +1397,16 @@ void AddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI, | |
| MI->eraseFromParent(); | ||
| } | ||
|
|
||
| // Check if an alloca is a catch block parameter | ||
| static bool isCatchParameter(const AllocaInst &AI) { | ||
| for (const Use &U : AI.uses()) { | ||
| if (isa<CatchPadInst>(U.getUser())) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /// Check if we want (and can) handle this alloca. | ||
| bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) { | ||
| auto [It, Inserted] = ProcessedAllocas.try_emplace(&AI); | ||
|
|
@@ -1417,7 +1427,11 @@ bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) { | |
| // swifterror allocas are register promoted by ISel | ||
| !AI.isSwiftError() && | ||
| // safe allocas are not interesting | ||
| !(SSGI && SSGI->isSafe(AI))); | ||
| !(SSGI && SSGI->isSafe(AI)) && | ||
| // Mitigation for https://github.com/google/sanitizers/issues/749 | ||
| // We don't instrument Windows catch-block parameters to avoid | ||
| // interfering with exception handling assumptions. | ||
| !(TargetTriple.isOSWindows() && isCatchParameter(AI))); | ||
|
||
|
|
||
| It->second = IsInteresting; | ||
| return IsInteresting; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.