File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -344,6 +344,19 @@ func NewFile(r io.ReaderAt) (*File, error) {
344
344
return nil , & FormatError {0 , "invalid ELF shstrndx" , shstrndx }
345
345
}
346
346
347
+ var wantPhentsize , wantShentsize int
348
+ switch f .Class {
349
+ case ELFCLASS32 :
350
+ wantPhentsize = 8 * 4
351
+ wantShentsize = 10 * 4
352
+ case ELFCLASS64 :
353
+ wantPhentsize = 2 * 4 + 6 * 8
354
+ wantShentsize = 4 * 4 + 6 * 8
355
+ }
356
+ if phnum > 0 && phentsize < wantPhentsize {
357
+ return nil , & FormatError {0 , "invalid ELF phentsize" , phentsize }
358
+ }
359
+
347
360
// Read program headers
348
361
f .Progs = make ([]* Prog , phnum )
349
362
for i := 0 ; i < phnum ; i ++ {
@@ -439,6 +452,10 @@ func NewFile(r io.ReaderAt) (*File, error) {
439
452
}
440
453
}
441
454
455
+ if shnum > 0 && shentsize < wantShentsize {
456
+ return nil , & FormatError {0 , "invalid ELF shentsize" , shentsize }
457
+ }
458
+
442
459
// Read section headers
443
460
f .Sections = make ([]* Section , shnum )
444
461
names := make ([]uint32 , shnum )
You can’t perform that action at this time.
0 commit comments