From 3800d98fbc53835f1e83eff17d0c5dc1461bfd49 Mon Sep 17 00:00:00 2001 From: guenther Date: Sun, 18 Jan 2015 05:30:58 +0000 Subject: [PATCH] The world is ELF: use instead of or Use a better test for an input being ELF: struct exec is dead and there are defines for the ELF magic. Reorder #includes and do some whitespace cleanup. Oh, and don't lead the fd if an input file isn't ELF. ok deraadt@ --- usr.sbin/crunchgen/crunchide.c | 40 +++++++++++++++++----------------- usr.sbin/crunchgen/elf_hide.c | 9 +++----- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/usr.sbin/crunchgen/crunchide.c b/usr.sbin/crunchgen/crunchide.c index 7c01e422cfd..1720dd08fde 100644 --- a/usr.sbin/crunchgen/crunchide.c +++ b/usr.sbin/crunchgen/crunchide.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crunchide.c,v 1.8 2014/03/16 20:45:47 guenther Exp $ */ +/* $OpenBSD: crunchide.c,v 1.9 2015/01/18 05:30:58 guenther Exp $ */ /* * Copyright (c) 1994 University of Maryland @@ -51,27 +51,27 @@ * that the final crunched binary BSS size is the max of all the * component programs' BSS sizes, rather than their sum. */ -#include -#include -#include -#include -#include -#include -#include + #include +#include #include #include + +#include +#include +#include +#include +#include + #include "mangle.h" -void usage(void); +void usage(void); -void add_to_keep_list(char *); -void add_file_to_keep_list(char *); +void add_to_keep_list(char *); +void add_file_to_keep_list(char *); -void hide_syms(char *); -#ifdef _NLIST_DO_ELF -void elf_hide(int, char *); -#endif +void hide_syms(char *); +void elf_hide(int, char *); int in_keep_list(char *symbol); int crunchide_main(int argc, char *argv[]); @@ -206,7 +206,7 @@ hide_syms(char *filename) close(inf); return; } - if (infstat.st_size < sizeof(struct exec)) { + if (infstat.st_size < sizeof(Elf_Ehdr)) { fprintf(stderr, "%s: short file\n", filename); close(inf); return; @@ -218,11 +218,11 @@ hide_syms(char *filename) return; } -#ifdef _NLIST_DO_ELF - if (buf[0] == 0x7f && (buf[1] == 'E' || buf[1] == 'O') && - buf[2] == 'L' && buf[3] == 'F') { + if (buf[0] == ELFMAG0 && buf[1] == ELFMAG1 && + buf[2] == ELFMAG2 && buf[3] == ELFMAG3) { elf_hide(inf, buf); return; } -#endif /* _NLIST_DO_ELF */ + + close(inf); } diff --git a/usr.sbin/crunchgen/elf_hide.c b/usr.sbin/crunchgen/elf_hide.c index 40ab159fd59..662d4e29070 100644 --- a/usr.sbin/crunchgen/elf_hide.c +++ b/usr.sbin/crunchgen/elf_hide.c @@ -1,4 +1,4 @@ -/* $OpenBSD: elf_hide.c,v 1.8 2014/05/20 01:25:24 guenther Exp $ */ +/* $OpenBSD: elf_hide.c,v 1.9 2015/01/18 05:30:58 guenther Exp $ */ /* * Copyright (c) 1997 Dale Rahn. @@ -29,6 +29,8 @@ #include #include #include +#include + #include #include #include @@ -36,12 +38,8 @@ #include #include #include -#include #include "mangle.h" -#ifdef _NLIST_DO_ELF -#include - extern int elf_mangle; void load_strtab(Elf_Ehdr * pehdr, char *pexe); @@ -445,4 +443,3 @@ renum_reloc_syms(Elf_Ehdr * ehdr, Symmap * symmap, int symtabsecnum) } } -#endif /* _NLIST_DO_ELF */ -- 2.20.1