diff options
| -rw-r--r-- | llvm/test/Object/yaml2obj-coff-invalid-alignment.test | 14 | ||||
| -rw-r--r-- | llvm/tools/yaml2obj/yaml2coff.cpp | 14 |
2 files changed, 26 insertions, 2 deletions
diff --git a/llvm/test/Object/yaml2obj-coff-invalid-alignment.test b/llvm/test/Object/yaml2obj-coff-invalid-alignment.test new file mode 100644 index 00000000000..f76f063dc44 --- /dev/null +++ b/llvm/test/Object/yaml2obj-coff-invalid-alignment.test @@ -0,0 +1,14 @@ +# RUN: not yaml2obj %s 2>&1 | FileCheck %s + +# CHECK: Section alignment is too large + +--- +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [] +sections: + - Name: '.text' + Characteristics: [] + SectionData: 00 + Alignment: 16384 +symbols: diff --git a/llvm/tools/yaml2obj/yaml2coff.cpp b/llvm/tools/yaml2obj/yaml2coff.cpp index 44535077e08..ca3057de177 100644 --- a/llvm/tools/yaml2obj/yaml2coff.cpp +++ b/llvm/tools/yaml2obj/yaml2coff.cpp @@ -76,14 +76,24 @@ struct COFFParser { unsigned Index = getStringIndex(Name); std::string str = utostr(Index); if (str.size() > 7) { - errs() << "String table got too large"; + errs() << "String table got too large\n"; return false; } Sec.Header.Name[0] = '/'; std::copy(str.begin(), str.end(), Sec.Header.Name + 1); } - Sec.Header.Characteristics |= (Log2_32(Sec.Alignment) + 1) << 20; + if (Sec.Alignment) { + if (Sec.Alignment > 8192) { + errs() << "Section alignment is too large\n"; + return false; + } + if (!isPowerOf2_32(Sec.Alignment)) { + errs() << "Section alignment is not a power of 2\n"; + return false; + } + Sec.Header.Characteristics |= (Log2_32(Sec.Alignment) + 1) << 20; + } } return true; } |

