Reject negative file descriptors in gzdopen() - #1301
Open
minnnjuuu wants to merge 1 commit into
Open
Conversation
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.
Reject negative file descriptors in
gzdopen()Summary
gzdopen()boundary.Problem
gzdopen()currently rejects onlyfd == -1. On Windows, the privategz_open()helper also usesfd == -2as an internal marker indicating thatpathis awchar_t *supplied bygzopen_w().A public call to
gzdopen(-2, "rb")therefore creates a narrowchar *diagnostic string and forwards it with the private marker. The Windows branch interprets that narrow allocation as a wide path. In an MSVC AddressSanitizer build, this produced a heap-buffer-overflow read inwcslen()through_wopen()and aborted the process.This issue occurs at a boundary where public
gzdopen()input overlaps with a special value used by the Windows implementation. The effect on an application depends on where itsfdvalue comes from and how it is validated. This change consistently rejects negative values at the API boundary, preventing them from colliding with the internal dispatch.Fix
File descriptors returned by the supported APIs are non-negative. Rejecting all negative values before constructing the diagnostic path prevents public callers from colliding with private path-opening markers.
The internal wide-character API remains unchanged:
gzopen_w()callsgz_open(path, -2, mode)directly and does not pass throughgzdopen().Testing
NULL.