Merge "crasher: add a case that leaks until OOM-kill."
am: f610d6db82
Change-Id: I475d8ca2e2959b66e19f71545e14f75f1ca8c202
This commit is contained in:
commit
0cb3d254a2
1 changed files with 11 additions and 1 deletions
|
|
@ -134,6 +134,14 @@ noinline void abuse_heap() {
|
||||||
free(buf); // GCC is smart enough to warn about this, but we're doing it deliberately.
|
free(buf); // GCC is smart enough to warn about this, but we're doing it deliberately.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noinline void leak() {
|
||||||
|
while (true) {
|
||||||
|
void* mapping =
|
||||||
|
mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
|
static_cast<volatile char*>(mapping)[0] = 'a';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
noinline void sigsegv_non_null() {
|
noinline void sigsegv_non_null() {
|
||||||
int* a = (int *)(&do_action);
|
int* a = (int *)(&do_action);
|
||||||
*a = 42;
|
*a = 42;
|
||||||
|
|
@ -160,8 +168,8 @@ static int usage() {
|
||||||
fprintf(stderr, " stack-overflow recurse until the stack overflows\n");
|
fprintf(stderr, " stack-overflow recurse until the stack overflows\n");
|
||||||
fprintf(stderr, " nostack crash with a NULL stack pointer\n");
|
fprintf(stderr, " nostack crash with a NULL stack pointer\n");
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, " heap-corruption cause a libc abort by corrupting the heap\n");
|
|
||||||
fprintf(stderr, " heap-usage cause a libc abort by abusing a heap function\n");
|
fprintf(stderr, " heap-usage cause a libc abort by abusing a heap function\n");
|
||||||
|
fprintf(stderr, " leak leak memory until we get OOM-killed\n");
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, " abort call abort()\n");
|
fprintf(stderr, " abort call abort()\n");
|
||||||
fprintf(stderr, " assert call assert() without a function\n");
|
fprintf(stderr, " assert call assert() without a function\n");
|
||||||
|
|
@ -265,6 +273,8 @@ noinline int do_action(const char* arg) {
|
||||||
return pthread_join(0, nullptr);
|
return pthread_join(0, nullptr);
|
||||||
} else if (!strcasecmp(arg, "heap-usage")) {
|
} else if (!strcasecmp(arg, "heap-usage")) {
|
||||||
abuse_heap();
|
abuse_heap();
|
||||||
|
} else if (!strcasecmp(arg, "leak")) {
|
||||||
|
leak();
|
||||||
} else if (!strcasecmp(arg, "SIGSEGV-unmapped")) {
|
} else if (!strcasecmp(arg, "SIGSEGV-unmapped")) {
|
||||||
char* map = reinterpret_cast<char*>(mmap(nullptr, sizeof(int), PROT_READ | PROT_WRITE,
|
char* map = reinterpret_cast<char*>(mmap(nullptr, sizeof(int), PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED | MAP_ANONYMOUS, -1, 0));
|
MAP_SHARED | MAP_ANONYMOUS, -1, 0));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue