mirror of
https://github.com/mandiant/GoReSym
synced 2026-06-08 15:40:15 +00:00
Resolve map initialization order bug
This commit is contained in:
+2
-2
@@ -244,6 +244,7 @@ func (f *File) SectionByType(typ SectionType) *Section {
|
||||
// NewFile creates a new File for accessing an ELF binary in an underlying reader.
|
||||
// The ELF binary is expected to start at position 0 in the ReaderAt.
|
||||
func NewFile(r io.ReaderAt) (*File, error) {
|
||||
|
||||
sr := io.NewSectionReader(r, 0, 1<<63-1)
|
||||
// Read and decode ELF identifier
|
||||
var ident [16]uint8
|
||||
@@ -255,6 +256,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
|
||||
}
|
||||
|
||||
f := new(File)
|
||||
f.dataAfterSectionCache = make(map[uint64][]byte)
|
||||
f.Class = Class(ident[EI_CLASS])
|
||||
switch f.Class {
|
||||
case ELFCLASS32:
|
||||
@@ -565,8 +567,6 @@ func NewFile(r io.ReaderAt) (*File, error) {
|
||||
return nil, &FormatError{shoff + int64(i*shentsize), "bad section name index", names[i]}
|
||||
}
|
||||
}
|
||||
|
||||
f.dataAfterSectionCache = make(map[uint64][]byte)
|
||||
return f, nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -231,6 +231,7 @@ func (f *File) Close() error {
|
||||
// The Mach-O binary is expected to start at position 0 in the ReaderAt.
|
||||
func NewFile(r io.ReaderAt) (*File, error) {
|
||||
f := new(File)
|
||||
f.dataAfterSectionCache = make(map[uint64][]byte)
|
||||
sr := io.NewSectionReader(r, 0, 1<<63-1)
|
||||
|
||||
// Read and decode Mach magic to determine byte order, size.
|
||||
@@ -449,7 +450,6 @@ func NewFile(r io.ReaderAt) (*File, error) {
|
||||
s.ReaderAt = s.sr
|
||||
}
|
||||
}
|
||||
f.dataAfterSectionCache = make(map[uint64][]byte)
|
||||
return f, nil
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -67,6 +67,7 @@ func (f *File) Close() error {
|
||||
// NewFile creates a new File for accessing a PE binary in an underlying reader.
|
||||
func NewFile(r io.ReaderAt) (*File, error) {
|
||||
f := new(File)
|
||||
f.dataAfterSectionCache = make(map[uint64][]byte)
|
||||
sr := io.NewSectionReader(r, 0, 1<<63-1)
|
||||
|
||||
var dosheader [96]byte
|
||||
@@ -172,8 +173,6 @@ func NewFile(r io.ReaderAt) (*File, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
f.dataAfterSectionCache = make(map[uint64][]byte)
|
||||
return f, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -188,6 +188,20 @@ func TestWeirdBins(t *testing.T) {
|
||||
t.Errorf("GoReSym found pclntab in a non-go binary, this is not possible.")
|
||||
}
|
||||
})
|
||||
|
||||
// reading the buildid with notes section at the start and alignment of 0 previously caused underflow in offset calculations
|
||||
t.Run("zero_elf_palignment", func(t *testing.T) {
|
||||
filePath := fmt.Sprintf("%s/test/weirdbins/%s", workingDirectory, "zero_elf_palignment")
|
||||
if _, err := os.Stat(filePath); errors.Is(err, os.ErrNotExist) {
|
||||
t.Errorf("Test file %s doesn't exist\n", filePath)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := main_impl(filePath, true, true, true, 0, "")
|
||||
if err == nil {
|
||||
t.Errorf("GoReSym found pclntab in a non-go binary, this is not possible.")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBig(t *testing.T) {
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user