Summary: The local and global quarantine sizes were not offering a distinction for 32-bit and 64-bit platforms. This is addressed with lower values for 32-bit. When writing additional tests for the quarantine, it was discovered that when calling some of the allocator interface function prior to any allocation operation having occured, the test would crash due to the allocator not being initialized. This was addressed by making sure the allocator is initialized for those scenarios. Relevant tests were added in interface.cpp and quarantine.cpp. Last change being the removal of the extraneous link dependencies for the tests thanks to rL293220, anf the addition of the gc-sections linker flag. Reviewers: kcc, alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29341 llvm-svn: 294037
40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
// RUN: %clang_scudo %s -o %t
|
|
// RUN: not %run %t malloc 2>&1 | FileCheck %s
|
|
// RUN: SCUDO_OPTIONS=QuarantineSizeMb=1 not %run %t quarantine 2>&1 | FileCheck %s
|
|
|
|
// Tests that header corruption of an allocated or quarantined chunk is caught.
|
|
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
ssize_t offset = sizeof(void *) == 8 ? 8 : 0;
|
|
|
|
assert(argc == 2);
|
|
|
|
if (!strcmp(argv[1], "malloc")) {
|
|
// Simulate a header corruption of an allocated chunk (1-bit)
|
|
void *p = malloc(1U << 4);
|
|
assert(p);
|
|
((char *)p)[-(offset + 1)] ^= 1;
|
|
free(p);
|
|
}
|
|
if (!strcmp(argv[1], "quarantine")) {
|
|
void *p = malloc(1U << 4);
|
|
assert(p);
|
|
free(p);
|
|
// Simulate a header corruption of a quarantined chunk
|
|
((char *)p)[-(offset + 2)] ^= 1;
|
|
// Trigger the quarantine recycle
|
|
for (int i = 0; i < 0x100; i++) {
|
|
p = malloc(1U << 16);
|
|
free(p);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// CHECK: ERROR: corrupted chunk header at address
|