Skip to content

Commit 0caa47f

Browse files
committed
[YAML] Don't validate Fill::Size after error
Size is required, so we don't know if it's in uninitialized state after the previous error. Triggers msan on llvm/test/tools/yaml2obj/ELF/custom-fill.yaml Pull Request: #123280
1 parent e696bc4 commit 0caa47f

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,9 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
17471747
std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
17481748
IO &io, std::unique_ptr<ELFYAML::Chunk> &C) {
17491749
if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) {
1750-
if (F->Pattern && F->Pattern->binary_size() != 0 && !F->Size)
1750+
// Can't check the `Size`, as it's required and may be left uninitialized by
1751+
// previous error.
1752+
if (!io.error() && F->Pattern && F->Pattern->binary_size() != 0 && !F->Size)
17511753
return "\"Size\" can't be 0 when \"Pattern\" is not empty";
17521754
return "";
17531755
}

llvm/lib/ObjectYAML/MachOYAML.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
346346
std::string
347347
MappingTraits<MachOYAML::Section>::validate(IO &IO,
348348
MachOYAML::Section &Section) {
349-
if (Section.content && Section.size < Section.content->binary_size())
349+
// Can't check the `size`, as it's required and may be left uninitialized by
350+
// previous error.
351+
if (!IO.error() && Section.content &&
352+
Section.size < Section.content->binary_size())
350353
return "Section size must be greater than or equal to the content size";
351354
return "";
352355
}

llvm/test/ObjectYAML/MachO/section_data.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,45 @@ LoadCommands:
159159
reserved2: 0x00000000
160160
reserved3: 0x00000000
161161
content: AA
162+
163+
## Case 4: Don't validate if size is missing.
164+
# RUN: not yaml2obj --docnum=4 %s -o %t1 2>&1 | FileCheck %s --check-prefix=CASE4
165+
# CASE4: error: missing required key 'size'
166+
# CASE4-NOT: error:
167+
# CASE4: error: failed to parse YAML
168+
169+
--- !mach-o
170+
FileHeader:
171+
magic: 0xFEEDFACF
172+
cputype: 0x01000007
173+
cpusubtype: 0x00000003
174+
filetype: 0x00000001
175+
ncmds: 1
176+
sizeofcmds: 232
177+
flags: 0x00002000
178+
reserved: 0x00000000
179+
LoadCommands:
180+
- cmd: LC_SEGMENT_64
181+
cmdsize: 232
182+
segname: ''
183+
vmaddr: 0
184+
vmsize: 4
185+
fileoff: 392
186+
filesize: 4
187+
maxprot: 7
188+
initprot: 7
189+
nsects: 1
190+
flags: 0
191+
Sections:
192+
- sectname: __data
193+
segname: __DATA
194+
addr: 0x0000000000000000
195+
content: AA
196+
offset: 0x00000188
197+
align: 2
198+
reloff: 0x00000000
199+
nreloc: 0
200+
flags: 0x00000000
201+
reserved1: 0x00000000
202+
reserved2: 0x00000000
203+
reserved3: 0x00000000

llvm/test/tools/yaml2obj/ELF/custom-fill.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ Sections:
158158
## Check that the "Size" field is mandatory.
159159
# RUN: not yaml2obj --docnum=5 2>&1 %s | FileCheck %s --check-prefix=NOSIZE
160160

161-
## NOSIZE: error: missing required key 'Size'
161+
# NOSIZE: error: missing required key 'Size'
162+
# NOSIZE-NOT: error:
163+
# NOSIZE: error: failed to parse YAML
162164

163165
--- !ELF
164166
FileHeader:

0 commit comments

Comments
 (0)