mod_mime_magic: reject negative indirect offset in mget - #715
Open
arshsmith1 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.
mget() only checks the upper bound of the offset it uses to index the sniff buffer, but that offset is a signed long, and for indirect ">(...)" rules it is derived from a value read out of the file being sniffed (offset = p->l + m->in.offset, where p->l comes from a BELONG/LELONG conversion that sign-extends bytes >= 0x80). A crafted file whose field yields a small negative offset slips through the guard, because offset + sizeof(union VALUETYPE) promotes offset to size_t and wraps to a small positive value, so the following memcpy reads up to 64 bytes before buf in magic_process. Reject negative offsets in both bounds checks so the read stays inside the buffer; valid rules resolve to a non-negative in-buffer position and are unaffected.