summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAchim Kriso <achim.kriso@student.kit.edu>2020-03-11 14:06:41 +0100
committerAndreas Fried <andreas.fried@kit.edu>2020-03-26 14:08:14 +0100
commit4e0d9f5b6a7b000bef1479d5d442273785889349 (patch)
tree849f99fe0bd7c8336037a1635ec3a725a56c7dd1
parent0b45c5d6cad8d5ad13e226060eb13e7875484838 (diff)
Fixed invalid pointer free
-rw-r--r--ir/opt/lfasan.c17
-rw-r--r--runtime/lfmalloc/src/lfinternal.c9
-rw-r--r--runtime/lfmalloc/src/lfmalloc.c2
3 files changed, 17 insertions, 11 deletions
diff --git a/ir/opt/lfasan.c b/ir/opt/lfasan.c
index 58f18f0..79b17a8 100644
--- a/ir/opt/lfasan.c
+++ b/ir/opt/lfasan.c
@@ -47,13 +47,14 @@ DEBUG_ONLY(static firm_dbg_module_t *dbg;)
*/
static void func_ptr_rename(ir_node *irn, void *env) {
(void) env;
- if (!is_Call(irn)) {
- return;
- }
- ir_node *func_ptr = get_Call_ptr(irn);
- if (!is_Address(func_ptr)) {
+ if (!is_Address(irn)) {
return;
}
+ ir_node *func_ptr = irn;
+ // ir_node *func_ptr = get_Call_ptr(irn);
+ // if (!is_Address(func_ptr)) {
+ // return;
+ // }
ir_entity *entity = get_irn_entity_attr(func_ptr);
const char* ld_name = get_entity_ld_name(entity);
@@ -198,7 +199,7 @@ static lfptr_meta *new_lfptr_meta(ir_node* base, ir_node *size, bool arithmetic)
}
/**
- * Analyzses irn to check if it is an allocation call.
+ * Analyzes irn to check if it is an allocation call.
* In this case it infers the metadata and returns it.
*/
static lfptr_meta *is_alloc_res(ir_node *irn) {
@@ -740,7 +741,7 @@ FIRM_API void lowfat_asan(ir_graph *irg) {
FIRM_DBG_REGISTER(dbg, "firm.opt.lfasan");
DB((dbg, LEVEL_1, "\n===> instrumenting %+F for lowfat adresssanitizer.\n", irg));
- dump_ir_graph(irg, "lf-asan-before");
+ //dump_ir_graph(irg, "lf-asan-before");
DB((dbg, LEVEL_2, "=> Replacing memory functions with lowfat alternatives.\n"));
irg_walk_graph(irg, NULL, func_ptr_rename, NULL);
@@ -787,7 +788,7 @@ FIRM_API void lowfat_asan(ir_graph *irg) {
pmap_destroy(lf_map);
set_optimize(opt_level);
- dump_ir_graph(irg, "lf-asan-after");
+ //dump_ir_graph(irg, "lf-asan-after");
ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_PHI_LIST);
confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE);
diff --git a/runtime/lfmalloc/src/lfinternal.c b/runtime/lfmalloc/src/lfinternal.c
index 51d90cd..0d6af92 100644
--- a/runtime/lfmalloc/src/lfinternal.c
+++ b/runtime/lfmalloc/src/lfinternal.c
@@ -98,6 +98,11 @@ uint64_t __lf_search_region_index(uint64_t size) {
return -1;
}
+// Only used to circumvent lfasan if the runtime is compiled with it.
+uint64_t __next_tail(uint64_t base, uint64_t offset) {
+ return base + offset;
+}
+
void* __allocate_in_region(size_t region_idx, size_t size) {
region* r = &region_freelists[region_idx];
if (r->head == NULL) {
@@ -115,7 +120,7 @@ void* __allocate_in_region(size_t region_idx, size_t size) {
void* p = r->head;
if (r->head == r->tail) { //Freelist filled: use remainder
- uint64_t new_tail = (uint64_t)r->tail + SIZES[region_idx];
+ uint64_t new_tail = __next_tail((uint64_t)r->tail, SIZES[region_idx]);
if (new_tail >= REGION_SIZE * region_idx + REGION_SIZE) {
r->tail = NULL;
@@ -269,7 +274,7 @@ void __lf_free(void* ptr) {
bool is_pow_two(size_t x) {
size_t s = 2;
- for (int i = 0; i < sizeof(size_t) * 8; i++) {
+ for (size_t i = 0; i < sizeof(size_t) * 8; i++) {
if (s == x)
return true;
else
diff --git a/runtime/lfmalloc/src/lfmalloc.c b/runtime/lfmalloc/src/lfmalloc.c
index a7fd9a2..999d4f6 100644
--- a/runtime/lfmalloc/src/lfmalloc.c
+++ b/runtime/lfmalloc/src/lfmalloc.c
@@ -79,7 +79,7 @@ int lf_posix_memalign(void **memptr, size_t alignment, size_t size) {
}
PRINTF_DBG("failed: posix_memalign ENOMEM\n");
return ENOMEM;
-};
+}
void *lf_aligned_alloc(size_t alignment, size_t size) {
PRINTF_DBG("called aligned_alloc, alignment = 0x%lx, size = 0x%lx\n", alignment, size);