Memory-safety fixes: uninitialized reads and a realloc leak#613
Open
matejk wants to merge 2 commits into
Open
Conversation
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.
1c27543 to
418c898
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two commits:
tape_get_pewsleaves*pewsunset on-LTFS_UNSUPPORTEDwhile the caller computespews + 10;ltfs_profiler_settested an unsetretwhen the volume had neither an iosched nor a device handle;_get_dumpderived a transfer length fromcap_bufwithout 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.reallocwas assigned straight back topriv.dk_list, so a failure overwrote the only pointer to the existing buffer with NULL and leaked it.