Report a missing __LINKEDIT segment instead of panicking - #835
Open
arpitjain099 wants to merge 1 commit into
Open
Report a missing __LINKEDIT segment instead of panicking#835arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
Segment() returns nil for a name it does not find, and the three places that look up __LINKEDIT (and __TEXT) during signing dereference the result straight away. A Mach-O without those segments is malformed, but quill can be handed one, and it panicked on a nil pointer rather than saying what was wrong with the input. Covers the same lookup in AddEmptyCodeSigningCmd, newCodeDirectoryFromMacho and the superblob patch step. The test drives AddEmptyCodeSigningCmd with a Mach-O that has no segments at all; it panics without the guards. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.
(*macho.File).Segmentreturns nil when it does not find the name, and the three places that look up__LINKEDIT(plus the__TEXTlookup next to one of them) use the result immediately:quill/macho/file.go,AddEmptyCodeSigningCmd:linkEditSeg.Offset + linkEditSeg.Fileszquill/sign/code_directory.go,newCodeDirectoryFromMacho:textSeg.Offset, andlinkEditSeg.Offset + linkEditSeg.Fileszon the no-existing-signature pathquill/sign/signing_super_blob.go:linkEditSegment.Filesz += numSbBytesA Mach-O without those segments is malformed, but quill can be handed one, and today it panics on a nil pointer instead of saying what is wrong with the input. Running
AddEmptyCodeSigningCmdagainst a file with no segments:Each site now returns an error naming the missing segment. Nothing else changes: on a well formed binary all four lookups succeed exactly as before.
The test builds a
Filewith an emptymacho.FilesoSegment("__LINKEDIT")is nil, and drivesAddEmptyCodeSigningCmd. It panics on main and passes here.go build ./...andgo vet ./quill/...are clean, andgo test ./quill/macho/passes.