Skip to content

UB: GlobalHeap should not be creatable from arbitrary pointers #17

@nathaniel-daniel

Description

@nathaniel-daniel

Since GlobalHeap can be created from an arbitrary pointer, and code assumes heaps always have valid pointers, it is easy to cause UB:

use mimalloc_rust::heap::GlobalHeap;
use mimalloc_rust::heap::MiMallocHeap;
use mimalloc_rust::*;

#[global_allocator]
static GLOBAL_MIMALLOC: GlobalMiMalloc = GlobalMiMalloc;

fn main() {
    let new_heap = GlobalHeap {
        heap: std::ptr::null_mut(),
    };

    GlobalMiMalloc::replace_by(&MiMallocHeap::new(new_heap));
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions