File tree Expand file tree Collapse file tree 4 files changed +5
-67
lines changed Expand file tree Collapse file tree 4 files changed +5
-67
lines changed Original file line number Diff line number Diff line change @@ -513,22 +513,15 @@ Expected<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const {
513
513
NumSections = First->sh_size ;
514
514
515
515
if (NumSections > UINT64_MAX / sizeof (Elf_Shdr))
516
- return createError (" invalid number of sections specified in the NULL "
517
- " section's sh_size field (" +
518
- Twine (NumSections) + " )" );
516
+ // TODO: this error is untested.
517
+ return createError (" section table goes past the end of file" );
519
518
520
519
const uint64_t SectionTableSize = NumSections * sizeof (Elf_Shdr);
521
- if (SectionTableOffset + SectionTableSize < SectionTableOffset)
522
- return createError (
523
- " invalid section header table offset (e_shoff = 0x" +
524
- Twine::utohexstr (SectionTableOffset) +
525
- " ) or invalid number of sections specified in the first section "
526
- " header's sh_size field (0x" +
527
- Twine::utohexstr (NumSections) + " )" );
528
520
529
521
// Section table goes past end of file!
530
522
if (SectionTableOffset + SectionTableSize > FileSize)
531
523
return createError (" section table goes past the end of file" );
524
+
532
525
return makeArrayRef (First, NumSections);
533
526
}
534
527
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ struct FileHeader {
77
77
llvm::yaml::Hex64 Entry;
78
78
79
79
Optional<llvm::yaml::Hex16> SHEntSize;
80
- Optional<llvm::yaml::Hex64 > SHOffset;
80
+ Optional<llvm::yaml::Hex16 > SHOffset;
81
81
Optional<llvm::yaml::Hex16> SHNum;
82
82
Optional<llvm::yaml::Hex16> SHStrNdx;
83
83
};
Original file line number Diff line number Diff line change @@ -552,58 +552,3 @@ FileHeader:
552
552
Sections:
553
553
- Name: .foo
554
554
Type: SHT_PROGBITS
555
-
556
- ## We report an error if the number of sections stored in sh_size
557
- ## is greater than UINT64_MAX / sizeof(Elf_Shdr) == 288230376151711743.
558
- ## Here we check that do not crash on a border value.
559
-
560
- # RUN: yaml2obj --docnum=26 %s -o %t26
561
- # RUN: not llvm-readobj -h %t26 2>&1 | FileCheck -DFILE=%t26 --check-prefix=INVALID-SEC-NUM1 %s
562
-
563
- # INVALID-SEC-NUM1: error: '[[FILE]]': invalid section header table offset (e_shoff = 0x40) or invalid number of sections specified in the first section header's sh_size field (0x3ffffffffffffff)
564
-
565
- --- !ELF
566
- FileHeader:
567
- Class: ELFCLASS64
568
- Data: ELFDATA2LSB
569
- Type: ET_REL
570
- Machine: EM_X86_64
571
- SHNum: 0x0
572
- Sections:
573
- - Type: SHT_NULL
574
- Size: 288230376151711743
575
-
576
- ## See above, but now we test the UINT64_MAX / sizeof(Elf_Shdr) value.
577
- ## The error is slightly different in this case.
578
-
579
- # RUN: yaml2obj --docnum=27 %s -o %t27
580
- # RUN: not llvm-readobj -h %t27 2>&1 | FileCheck -DFILE=%t27 --check-prefix=INVALID-SEC-NUM2 %s
581
-
582
- # INVALID-SEC-NUM2: error: '[[FILE]]': invalid number of sections specified in the NULL section's sh_size field (288230376151711744)
583
-
584
- --- !ELF
585
- FileHeader:
586
- Class: ELFCLASS64
587
- Data: ELFDATA2LSB
588
- Type: ET_REL
589
- Machine: EM_X86_64
590
- SHNum: 0x0
591
- Sections:
592
- - Type: SHT_NULL
593
- Size: 288230376151711744
594
-
595
- ## Check the case when SHOffset is too large, but SHNum is not. SHOffset + SHNum overflows the uint64 type.
596
-
597
- # RUN: yaml2obj --docnum=28 %s -o %t28
598
- # RUN: not llvm-readobj -h %t28 2>&1 | FileCheck -DFILE=%t28 --check-prefix=INVALID-SEC-NUM3 %s
599
-
600
- # INVALID-SEC-NUM3: error: '[[FILE]]': invalid section header table offset (e_shoff = 0xffffffffffffffff) or invalid number of sections specified in the first section header's sh_size field (0x1)
601
-
602
- --- !ELF
603
- FileHeader:
604
- Class: ELFCLASS64
605
- Data: ELFDATA2LSB
606
- Type: ET_REL
607
- Machine: EM_X86_64
608
- SHOffset: 0xffffffffffffffff
609
- SHNum: 0x1
Original file line number Diff line number Diff line change @@ -244,7 +244,7 @@ void ELFState<ELFT>::initELFHeader(Elf_Ehdr &Header) {
244
244
// Immediately following the ELF header and program headers.
245
245
Header.e_shoff =
246
246
Doc.Header .SHOffset
247
- ? (typename ELFT::uint)( *Doc.Header .SHOffset )
247
+ ? (uint16_t ) *Doc.Header .SHOffset
248
248
: sizeof (Header) + sizeof (Elf_Phdr) * Doc.ProgramHeaders .size ();
249
249
Header.e_shnum =
250
250
Doc.Header .SHNum ? (uint16_t )*Doc.Header .SHNum : SN2I.size () + 1 ;
You can’t perform that action at this time.
0 commit comments