Skip to content

memtrack: VLA from map2check_map_non_static_alloca is a leak and takes size in bytes (SD-12) #38

Open

Description

@hbgit

map2check_map_non_static_alloca (used for variable-length arrays) differs from the legacy call in two ways. Documented as SD-12 in docs/semantic-deltas.md (PR #35).

  1. It marks the record dynamic, so with map2check_set_memcleanup() on, a VLA that goes out of scope reports MEMSAFETY_MEMCLEANUP.
  2. It stores size in bytes; the legacy contract passes an element count and multiplies by size_of_primitive. A caller following the legacy contract registers a block that is too small, and loads past it report MEMSAFETY_DEREF.

Reproduce (links against libmap2check.a, no features):

map2check_init();
int n = 4; int vla[n];
map2check_map_non_static_alloca("vla", vla, sizeof(vla), sizeof(int), 3, 0);
map2check_set_memcleanup();
map2check_check_mem_endprog();   /* MemsafetyMemcleanup */

map2check_reset();
map2check_map_non_static_alloca("vla", vla, n, sizeof(int), 3, 0);  /* legacy: element count */
map2check_check_load(&vla[2], 4, 0, sizeof(int), "main");          /* MemsafetyDeref; legacy: valid */

Legacy: map2check_non_static_alloca calls map2check_alloca(name, ptr, size * size_of_primitive, ...), a static slot (lib_old/AnalysisModeMemtrack.c:366-377 on origin/refactory_memory_log).

Likely cause: entry.set_malloc() and size as usize in map2check_map_non_static_alloca (rust/src/ffi.rs). The Rust semantics were reconstructed without the original source (see docs/api-deltas.md).

Pinned today by: rust/src/ffi_tests.rs::map_non_static_alloca_records_dynamic_slot, ::non_static_alloca_is_reported_as_leak_at_end_of_program, ::non_static_alloca_size_is_bytes_not_element_count.

Acceptance criteria:

  • Decide both points, considering the signature the Map2Check pass uses (map2check_non_static_alloca(ptr, ptr, i64, i64, i64, i64), see Add a compatibility layer for current Map2Check passes #21).
  • Update the tests, SD-12 and the map2check_map_non_static_alloca section of docs/api-deltas.md in the same change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions