diff options
Diffstat (limited to 'test/libelf/tset/common')
| -rw-r--r-- | test/libelf/tset/common/Makefile | 3 | ||||
| -rw-r--r-- | test/libelf/tset/common/ehdr-malformed-1.yaml | 23 | ||||
| -rw-r--r-- | test/libelf/tset/common/ehdr_template.m4 | 50 |
3 files changed, 74 insertions, 2 deletions
diff --git a/test/libelf/tset/common/Makefile b/test/libelf/tset/common/Makefile index 5dd5bf9c1a5b..8f8400a39753 100644 --- a/test/libelf/tset/common/Makefile +++ b/test/libelf/tset/common/Makefile @@ -1,10 +1,11 @@ -# $Id: Makefile 1719 2011-08-12 08:24:14Z jkoshy $ +# $Id: Makefile 3690 2019-02-23 22:51:13Z jkoshy $ TOP= ../../../.. YAML_FILES= check_elf \ getclass \ ehdr \ + ehdr-malformed-1 \ fsize \ newehdr newscn newscn2 \ phdr \ diff --git a/test/libelf/tset/common/ehdr-malformed-1.yaml b/test/libelf/tset/common/ehdr-malformed-1.yaml new file mode 100644 index 000000000000..d7c000f47aed --- /dev/null +++ b/test/libelf/tset/common/ehdr-malformed-1.yaml @@ -0,0 +1,23 @@ +%YAML 1.1 +# $Id$ +--- +ehdr: !Ehdr + e_ident: !Ident # e_ident[] members + ei_class: ELFCLASSNONE + ei_data: ELFDATANONE + ei_osabi: ELFOSABI_SYSV + ei_abiversion: 0 + # other members + e_type: 0xFF03 + e_machine: 0x42 + e_version: 0xFFFFFFFF + e_entry: 0xFFFFFFFFFFFFFFFF + e_phoff: 0xFFFFFFFFFFFFFFFF + e_shoff: 0xFFFFFFFFFFFFFFFF + e_flags: [ 64, 8, 2, 1] + e_ehsize: 62 + e_phentsize: 228 + e_phnum: 0 + e_shentsize: 8192 + e_shnum: 0 + e_shstrndx: 0 diff --git a/test/libelf/tset/common/ehdr_template.m4 b/test/libelf/tset/common/ehdr_template.m4 index 872e0ff3b7c8..31cacd4de541 100644 --- a/test/libelf/tset/common/ehdr_template.m4 +++ b/test/libelf/tset/common/ehdr_template.m4 @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ehdr_template.m4 3174 2015-03-27 17:13:41Z emaste $ + * $Id: ehdr_template.m4 3703 2019-03-02 20:41:03Z jkoshy $ */ include(`elfts.m4') @@ -367,3 +367,51 @@ tcElfWrongSize$1(void) FN(`LSB') FN(`MSB') + +/* + * Verify that malformed ELF objects are rejected. + */ + +undefine(`FN') +define(`FN',` +void +tcMalformed1$1(void) +{ + int error, fd, result; + Elf *e; + char *fn; + TS_EHDR *eh; + + TP_CHECK_INITIALIZATION(); + + TP_ANNOUNCE("TS_ICNAME with a malformed ELF header " + "fails with ELF_E_HEADER."); + + e = NULL; + fd = -1; + fn = "ehdr-malformed-1.TOLOWER($1)`'TS_EHDRSZ"; + result = TET_UNRESOLVED; + + _TS_OPEN_FILE(e, fn, ELF_C_READ, fd, goto done;); + + error = 0; + if ((eh = TS_ICFUNC`'(e)) != NULL) { + TP_FAIL("\"%s\" TS_ICNAME`'() succeeded.", fn); + goto done; + } else if ((error = elf_errno()) != ELF_E_HEADER) { + TP_FAIL("\"%s\" incorrect error (%d).", fn, error); + goto done; + } + + result = TET_PASS; + +done: + if (e) + (void) elf_end(e); + if (fd != -1) + (void) close(fd); + tet_result(result); +}') + +FN(`LSB') +FN(`MSB') |
