diff options
author | Chris Lattner <sabre@nondot.org> | 2010-07-20 20:19:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-07-20 20:19:24 +0000 |
commit | 6c552c1d5f47fbba00e6268d96a26ad026f2da2a (patch) | |
tree | 0db7f53769c0611ae1901d17e402351a18eef312 /lib/CodeGen/CodeGenFunction.h | |
parent | f033f1da4a34f8df6e95e9929dc04ff54bb8fb01 (diff) |
implement rdar://5739832 - operator new should check for overflow in multiply,
causing clang to compile this code into something that correctly throws a
length error, fixing a potential integer overflow security attack:
void *test(long N) {
return new int[N];
}
int main() {
test(1L << 62);
}
We do this even when exceptions are disabled, because it is better for the
code to abort than for the attack to succeed.
This is heavily based on a patch that Fariborz wrote.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108915 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.h')
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 778604b217..1a117cab96 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -656,7 +656,7 @@ private: llvm::BasicBlock *TerminateLandingPad; llvm::BasicBlock *TerminateHandler; - llvm::BasicBlock *TrapBB; + llvm::BasicBlock *TrapBB, *ThrowLengthErrorBB; public: CodeGenFunction(CodeGenModule &cgm); @@ -1542,7 +1542,11 @@ public: /// getTrapBB - Create a basic block that will call the trap intrinsic. We'll /// generate a branch around the created basic block as necessary. - llvm::BasicBlock* getTrapBB(); + llvm::BasicBlock *getTrapBB(); + + /// getThrowLengthErrorBB - Create a basic block that will call + /// std::__throw_length_error to throw a std::length_error exception. + llvm::BasicBlock *getThrowLengthErrorBB(); /// EmitCallArg - Emit a single call argument. RValue EmitCallArg(const Expr *E, QualType ArgType); |