From 31e976ee9c034c1d7bf683104a7b77a3ac92ac4d Mon Sep 17 00:00:00 2001 From: mcbride Date: Wed, 1 Jan 2014 09:24:54 +0000 Subject: [PATCH] Fix 'make bsd.umg' by skipping PT_OPENBSD_RANDOMIZE segments, as well as other innocuous segment types (PT_NOTE, PT_NULL). Handle PT_LOAD, fail on any others. Thanks kettenis and millert for feedback ok deraadt --- usr.sbin/mkuboot/copy_elf.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/usr.sbin/mkuboot/copy_elf.c b/usr.sbin/mkuboot/copy_elf.c index b6aff8bad1a..60e5e77e531 100644 --- a/usr.sbin/mkuboot/copy_elf.c +++ b/usr.sbin/mkuboot/copy_elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: copy_elf.c,v 1.4 2013/12/31 07:15:57 mcbride Exp $ */ +/* $OpenBSD: copy_elf.c,v 1.5 2014/01/01 09:24:54 mcbride Exp $ */ /* * Copyright (c) 2013 Miodrag Vallat. @@ -137,11 +137,30 @@ ELFNAME(copy_elf)(int ifd, const char *iname, int ofd, const char *oname, err(1, "%s", iname); #ifdef DEBUG - fprintf(stderr, "vaddr %p offset %p filesz %p memsz %p\n", - elfoff2h(phdr.p_vaddr), elfoff2h(phdr.p_offset), - elfoff2h(phdr.p_filesz), elfoff2h(phdr.p_memsz)); + fprintf(stderr, + "vaddr %p type %#x offset %p filesz %p memsz %p\n", + elfoff2h(phdr.p_vaddr), letoh32(phdr.p_type), + elfoff2h(phdr.p_offset), elfoff2h(phdr.p_filesz), + elfoff2h(phdr.p_memsz)); #endif - if (i == 0) + + switch (letoh32(phdr.p_type)) { + case PT_LOAD: + break; + case PT_NULL: + case PT_NOTE: + case PT_OPENBSD_RANDOMIZE: +#ifdef DEBUG + fprintf(stderr, "skipping segment type %#x\n", + letoh32(phdr.p_type)); +#endif + continue; + default: + errx(1, "unexpected segment type %#x", + letoh32(phdr.p_type)); + } + + if (i == 0) vaddr = elfoff2h(phdr.p_vaddr); else if (vaddr != elfoff2h(phdr.p_vaddr)) { #ifdef DEBUG -- 2.20.1