mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Add files via upload
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
| test.cpp:30:15:30:26 | call to operator new[] | memory allocation error check is incorrect or missing |
|
||||
| test.cpp:38:9:38:20 | call to operator new[] | memory allocation error check is incorrect or missing |
|
||||
| test.cpp:50:13:50:38 | call to operator new[] | memory allocation error check is incorrect or missing |
|
||||
| test.cpp:51:22:51:47 | call to operator new[] | memory allocation error check is incorrect or missing |
|
||||
| test.cpp:53:18:53:43 | call to operator new[] | memory allocation error check is incorrect or missing |
|
||||
@@ -0,0 +1 @@
|
||||
experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql
|
||||
@@ -0,0 +1,97 @@
|
||||
#define NULL ((void*)0)
|
||||
class exception {};
|
||||
|
||||
namespace std{
|
||||
struct nothrow_t {};
|
||||
typedef unsigned long size_t;
|
||||
class bad_alloc{
|
||||
const char* what() const throw();
|
||||
};
|
||||
extern const std::nothrow_t nothrow;
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
void* operator new(std::size_t _Size);
|
||||
void* operator new[](std::size_t _Size);
|
||||
void* operator new( std::size_t count, const std::nothrow_t& tag );
|
||||
void* operator new[]( std::size_t count, const std::nothrow_t& tag );
|
||||
|
||||
void badNew_0_0()
|
||||
{
|
||||
while (true) {
|
||||
new int[100];
|
||||
if(!(new int[100]))
|
||||
return;
|
||||
}
|
||||
}
|
||||
void badNew_0_1()
|
||||
{
|
||||
int * i = new int[100];
|
||||
if(i == 0)
|
||||
return;
|
||||
if(!i)
|
||||
return;
|
||||
if(i == NULL)
|
||||
return;
|
||||
int * j;
|
||||
j = new int[100];
|
||||
if(j == 0)
|
||||
return;
|
||||
if(!j)
|
||||
return;
|
||||
if(j == NULL)
|
||||
return;
|
||||
}
|
||||
void badNew_1_0()
|
||||
{
|
||||
try {
|
||||
while (true) {
|
||||
new(std::nothrow) int[100];
|
||||
int* p = new(std::nothrow) int[100];
|
||||
int* p1;
|
||||
p1 = new(std::nothrow) int[100];
|
||||
}
|
||||
} catch (const exception &){//const std::bad_alloc& e) {
|
||||
// std::cout << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
void badNew_1_1()
|
||||
{
|
||||
while (true) {
|
||||
int* p = new(std::nothrow) int[100];
|
||||
new(std::nothrow) int[100];
|
||||
}
|
||||
}
|
||||
|
||||
void goodNew_0_0()
|
||||
{
|
||||
try {
|
||||
while (true) {
|
||||
new int[100];
|
||||
}
|
||||
} catch (const exception &){//const std::bad_alloc& e) {
|
||||
// std::cout << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void goodNew_1_0()
|
||||
{
|
||||
while (true) {
|
||||
int* p = new(std::nothrow) int[100];
|
||||
if (p == nullptr) {
|
||||
// std::cout << "Allocation returned nullptr\n";
|
||||
break;
|
||||
}
|
||||
int* p1;
|
||||
p1 = new(std::nothrow) int[100];
|
||||
if (p1 == nullptr) {
|
||||
// std::cout << "Allocation returned nullptr\n";
|
||||
break;
|
||||
}
|
||||
if (new(std::nothrow) int[100] == nullptr) {
|
||||
// std::cout << "Allocation returned nullptr\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user