Skip to content

Memory-safety fixes: uninitialized reads and a realloc leak#613

Open
matejk wants to merge 2 commits into
LinearTapeFileSystem:mainfrom
matejk:fix/memory-safety
Open

Memory-safety fixes: uninitialized reads and a realloc leak#613
matejk wants to merge 2 commits into
LinearTapeFileSystem:mainfrom
matejk:fix/memory-safety

Conversation

@matejk

@matejk matejk commented Jun 12, 2026

Copy link
Copy Markdown

Two commits:

  • Reads of uninitialized values on error paths (4 sites): tape_get_pews leaves *pews unset on -LTFS_UNSUPPORTED while the caller computes pews + 10; ltfs_profiler_set tested an unset ret when the volume had neither an iosched nor a device handle; _get_dump derived a transfer length from cap_buf without checking the READ BUFFER result; the ICU normalize callers compared the output pointer against the input before checking the return code, reading uninitialized memory and potentially leaking the input buffer.
  • Key-list leak in the simple KMI: realloc was assigned straight back to priv.dk_list, so a failure overwrote the only pointer to the existing buffer with NULL and leaked it.

@vandelvan vandelvan requested review from XV02, madjesc and syaoraang June 12, 2026 20:55
matejk added 2 commits June 17, 2026 22:06
Four sites used a value that may never have been set:
- tape_get_pews leaves *pews unset on -LTFS_UNSUPPORTED, which the
  caller treats as non-fatal before computing pews + 10.
- ltfs_profiler_set left ret unset when the volume had neither an
  iosched nor a device handle, then tested it.
- _get_dump derived a transfer length from cap_buf without checking
  the READ BUFFER result, so a failed read produced a garbage length.
- the ICU normalize helpers leave their output pointer unset on error,
  but the callers compared that pointer against the input (to decide
  whether to free a no-op result) before checking the return code,
  reading uninitialized memory and potentially leaking the input
  buffer.

Initialize pews and ret, check the READ BUFFER result, and check the
normalize return code before the pointer comparison in all five
callers.
realloc was assigned back to priv.dk_list, so a failure overwrote the
only pointer to the existing buffer with NULL and leaked it. Use a
temporary and free the original on failure.
@matejk matejk force-pushed the fix/memory-safety branch from 1c27543 to 418c898 Compare June 17, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant