Author: emaste Date: Fri Sep 27 19:07:11 2019 New Revision: 352809 URL: https://svnweb.freebsd.org/changeset/base/352809
Log: controlelf: exit with error if file endianness does not match host We need to add support for cross-endian operation, but until that's done just exit with an error rather than misbehaving. Modified: head/tools/tools/controlelf/controlelf.c Modified: head/tools/tools/controlelf/controlelf.c ============================================================================== --- head/tools/tools/controlelf/controlelf.c Fri Sep 27 18:49:13 2019 (r352808) +++ head/tools/tools/controlelf/controlelf.c Fri Sep 27 19:07:11 2019 (r352809) @@ -30,6 +30,7 @@ #include <sys/param.h> #include <sys/elf_common.h> +#include <sys/endian.h> #include <sys/stat.h> #include <err.h> @@ -70,6 +71,12 @@ static struct option long_opts[] = { { NULL, 0, NULL, 0 } }; +#if BYTE_ORDER == LITTLE_ENDIAN +#define SUPPORTED_ENDIAN ELFDATA2LSB +#else +#define SUPPORTED_ENDIAN ELFDATA2MSB +#endif + int main(int argc, char **argv) { @@ -140,6 +147,15 @@ main(int argc, char **argv) if (gelf_getehdr(elf, &ehdr) == NULL) { warnx("gelf_getehdr: %s", elf_errmsg(-1)); + retval = 1; + goto fail; + } + /* + * XXX need to support cross-endian operation, but for now + * exit on error rather than misbehaving. + */ + if (ehdr.e_ident[EI_DATA] != SUPPORTED_ENDIAN) { + warnx("file endianness must match host"); retval = 1; goto fail; } _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"