LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package elf implements access to ELF object files. | 5 // Package elf implements access to ELF object files. |
6 package elf | 6 package elf |
7 | 7 |
8 import ( | 8 import ( |
9 "bytes" | 9 "bytes" |
10 "debug/dwarf" | 10 "debug/dwarf" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return nil, &FormatError{0, "mismatched ELF version", v} | 265 return nil, &FormatError{0, "mismatched ELF version", v} |
266 } | 266 } |
267 phoff = int64(hdr.Phoff) | 267 phoff = int64(hdr.Phoff) |
268 phentsize = int(hdr.Phentsize) | 268 phentsize = int(hdr.Phentsize) |
269 phnum = int(hdr.Phnum) | 269 phnum = int(hdr.Phnum) |
270 shoff = int64(hdr.Shoff) | 270 shoff = int64(hdr.Shoff) |
271 shentsize = int(hdr.Shentsize) | 271 shentsize = int(hdr.Shentsize) |
272 shnum = int(hdr.Shnum) | 272 shnum = int(hdr.Shnum) |
273 shstrndx = int(hdr.Shstrndx) | 273 shstrndx = int(hdr.Shstrndx) |
274 } | 274 } |
275 » if shstrndx < 0 || shstrndx > shnum { | 275 |
| 276 » if shnum > 0 && shoff > 0 && (shstrndx < 0 || shstrndx >= shnum) { |
276 return nil, &FormatError{0, "invalid ELF shstrndx", shstrndx} | 277 return nil, &FormatError{0, "invalid ELF shstrndx", shstrndx} |
277 } | 278 } |
278 | 279 |
279 // Read program headers | 280 // Read program headers |
280 f.Progs = make([]*Prog, phnum) | 281 f.Progs = make([]*Prog, phnum) |
281 for i := 0; i < phnum; i++ { | 282 for i := 0; i < phnum; i++ { |
282 off := phoff + int64(i)*int64(phentsize) | 283 off := phoff + int64(i)*int64(phentsize) |
283 sr.Seek(off, os.SEEK_SET) | 284 sr.Seek(off, os.SEEK_SET) |
284 p := new(Prog) | 285 p := new(Prog) |
285 switch f.Class { | 286 switch f.Class { |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 } | 766 } |
766 if t == tag { | 767 if t == tag { |
767 s, ok := getString(str, int(v)) | 768 s, ok := getString(str, int(v)) |
768 if ok { | 769 if ok { |
769 all = append(all, s) | 770 all = append(all, s) |
770 } | 771 } |
771 } | 772 } |
772 } | 773 } |
773 return all, nil | 774 return all, nil |
774 } | 775 } |
LEFT | RIGHT |