Skip to content

[BUG] Harden malloc_aligned_4k (Overflow Guard + Quiet Failure) #45

@k8ika0s

Description

@k8ika0s

Proposed PR branch: qe/issue-06-malloc4k-hardening

Category: Bug (memory safety hardening)

Problem

  • malloc_aligned_4k() must reject sizes that overflow internal calculations.
  • Library code paths should not print to stderr on allocation failures.

Justification / why this is needed

  • Overflow in allocation-size math is a classic memory safety footgun; even if
    not exploitable, it can cause crashes and silent data corruption.
  • Printing to stderr from a library is hostile to integrators (pollutes logs,
    breaks structured logging, and can leak details in restricted environments).
  • Baseline+regtests showed the overflow guard + quiet-failure expectations
    failing, while the enhanced tree passes.

Proposed change

  • Add explicit overflow checks.
  • Remove stderr prints on failure paths.
  • Add regression tests for overflow guard and “quiet failure”.

Acceptance criteria

  • Overflow-size requests return NULL.
  • No unexpected stderr output for allocation failure paths.
  • Regression tests cover both behaviors.

Test plan

  • make test (expects tests/testDriver_malloc4k.c to pass).

References

  • Baseline report: artifacts/FINAL_BASELINE_ENHANCEMENT_REPORT.md shows two
    malloc4k regressions failing on baseline+regtests and passing in enhanced.
  • Key files: zdnn/malloc4k.c, tests/testDriver_malloc4k.c.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions