]> Cypherpunks repositories - gostls13.git/commitdiff
Decode overlapping section names correctly.
authorAustin Clements <aclements@csail.mit.edu>
Sat, 22 Aug 2009 01:30:20 +0000 (18:30 -0700)
committerAustin Clements <aclements@csail.mit.edu>
Sat, 22 Aug 2009 01:30:20 +0000 (18:30 -0700)
R=rsc
APPROVED=rsc
DELTA=23  (14 added, 8 deleted, 1 changed)
OCL=33699
CL=33705

usr/austin/sym/elf.go

index 5d92ce00fa97f63c4165af45d02a0cd8aaf5bfca..95b7cc41c4a87bcad4febc96b0642e71cc04f1c2 100644 (file)
@@ -168,18 +168,10 @@ func NewElf(r io.ReadSeeker) (*Elf, os.Error) {
        }
        blob := make([]byte, e.Sections[shstrndx].Size);
        n, err = io.ReadFull(r, blob);
-       strings := make(map[uint32] string);
-       strStart := uint32(0);
-       for i, c := range blob {
-               if c == 0 {
-                       strings[strStart] = string(blob[strStart:i]);
-                       strStart = uint32(i+1);
-               }
-       }
 
        for i, s := range e.Sections {
                var ok bool;
-               s.Name, ok = strings[secNames[i]];
+               s.Name, ok = getString(blob, int(secNames[i]));
                if !ok {
                        return nil, &FormatError{start + shoff + int64(i*shentsize), "bad section name", secNames[i]};
                }
@@ -188,6 +180,20 @@ func NewElf(r io.ReadSeeker) (*Elf, os.Error) {
        return e, nil;
 }
 
+// getString extracts a string from an ELF string table.
+func getString(section []byte, index int) (string, bool) {
+       if index < 0 || index >= len(section) {
+               return "", false;
+       }
+
+       for end := index; end < len(section); end++ {
+               if section[end] == 0 {
+                       return string(section[index:end]), true;
+               }
+       }
+       return "", false;
+}
+
 // Section returns a section with the given name, or nil if no such
 // section exists.
 func (e *Elf) Section(name string) *Section {