[Midnightbsd-cvs] src [10824] trunk/usr.sbin/crunch/crunchide: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jun 10 16:25:04 EDT 2018


Revision: 10824
          http://svnweb.midnightbsd.org/src/?rev=10824
Author:   laffer1
Date:     2018-06-10 16:25:03 -0400 (Sun, 10 Jun 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/usr.sbin/crunch/crunchide/Makefile
    trunk/usr.sbin/crunch/crunchide/crunchide.1
    trunk/usr.sbin/crunch/crunchide/crunchide.c
    trunk/usr.sbin/crunch/crunchide/exec_elf32.c
    trunk/usr.sbin/crunch/crunchide/exec_elf64.c
    trunk/usr.sbin/crunch/crunchide/extern.h

Property Changed:
----------------
    trunk/usr.sbin/crunch/crunchide/crunchide.1

Modified: trunk/usr.sbin/crunch/crunchide/Makefile
===================================================================
--- trunk/usr.sbin/crunch/crunchide/Makefile	2018-06-10 20:23:48 UTC (rev 10823)
+++ trunk/usr.sbin/crunch/crunchide/Makefile	2018-06-10 20:25:03 UTC (rev 10824)
@@ -1,23 +1,10 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/crunch/crunchide/Makefile 292423 2015-12-18 03:06:39Z emaste $
 
 PROG=   crunchide
-SRCS=	crunchide.c
+SRCS=	crunchide.c exec_elf32.c exec_elf64.c
 
-TARGET_ARCH?=	${MACHINE_ARCH}
-
-.if ${TARGET_ARCH} == i386 && ${MACHINE_ARCH} == i386
-CFLAGS+=-DNLIST_AOUT
-SRCS+=	exec_aout.c
-.endif
-
-.if ${TARGET_ARCH} == ia64 || ${TARGET_ARCH} == powerpc64 || \
-    ${TARGET_ARCH} == sparc64 || ${TARGET_ARCH} == amd64
-CFLAGS+=-DNLIST_ELF64
-SRCS+=	exec_elf64.c
+CFLAGS+=-DNLIST_ELF32 -DNLIST_ELF64
 exec_elf64.o: exec_elf32.c
-.else
-CFLAGS+=-DNLIST_ELF32
-SRCS+=	exec_elf32.c
-.endif
 
 .include <bsd.prog.mk>

Modified: trunk/usr.sbin/crunch/crunchide/crunchide.1
===================================================================
--- trunk/usr.sbin/crunch/crunchide/crunchide.1	2018-06-10 20:23:48 UTC (rev 10823)
+++ trunk/usr.sbin/crunch/crunchide/crunchide.1	2018-06-10 20:25:03 UTC (rev 10824)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" Copyright (c) 1994 University of Maryland
 .\" All Rights Reserved.
@@ -22,7 +23,7 @@
 .\" Author: James da Silva, Systems Design and Analysis Group
 .\"			   Computer Science Department
 .\"			   University of Maryland at College Park
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.sbin/crunch/crunchide/crunchide.1 131500 2004-07-02 23:13:00Z ru $
 .\"
 .Dd June 14, 1994
 .Dt CRUNCHIDE 1


Property changes on: trunk/usr.sbin/crunch/crunchide/crunchide.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/crunch/crunchide/crunchide.c
===================================================================
--- trunk/usr.sbin/crunch/crunchide/crunchide.c	2018-06-10 20:23:48 UTC (rev 10823)
+++ trunk/usr.sbin/crunch/crunchide/crunchide.c	2018-06-10 20:25:03 UTC (rev 10824)
@@ -1,5 +1,5 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: crunchide.c,v 1.8 1997/11/01 06:51:45 lukem Exp $	*/
-/* $MidnightBSD$ */
 /*
  * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
  * Copyright (c) 1994 University of Maryland
@@ -59,11 +59,16 @@
  *	  that the final crunched binary BSS size is the max of all the
  *	  component programs' BSS sizes, rather than their sum.
  */
+
 #include <sys/cdefs.h>
 #ifndef lint
 __RCSID("$NetBSD: crunchide.c,v 1.8 1997/11/01 06:51:45 lukem Exp $");
 #endif
+__FBSDID("$FreeBSD: stable/10/usr.sbin/crunch/crunchide/crunchide.c 292422 2015-12-18 02:34:01Z emaste $");
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -70,9 +75,6 @@
 #include <string.h>
 #include <fcntl.h>
 #include <a.out.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/errno.h>
 
 #include "extern.h"
 
@@ -89,9 +91,8 @@
 
 int main(int, char *[]);
 
-int main(argc, argv)
-int argc;
-char **argv;
+int
+main(int argc, char **argv)
 {
     int ch, errors;
 
@@ -127,7 +128,8 @@
     return errors;
 }
 
-void usage(void)
+void
+usage(void)
 {
     fprintf(stderr,
 	    "usage: %s [-k <symbol-name>] [-f <keep-list-file>] <files> ...\n",
@@ -142,7 +144,8 @@
     char *sym;
 } *keep_list;
 
-void add_to_keep_list(char *symbol)
+void
+add_to_keep_list(char *symbol)
 {
     struct keep *newp, *prevp, *curp;
     int cmp;
@@ -167,7 +170,8 @@
     else keep_list = newp;
 }
 
-int in_keep_list(const char *symbol)
+int
+in_keep_list(const char *symbol)
 {
     struct keep *curp;
     int cmp;
@@ -180,7 +184,8 @@
     return curp && cmp == 0;
 }
 
-void add_file_to_keep_list(char *filename)
+void
+add_file_to_keep_list(char *filename)
 {
     FILE *keepf;
     char symbol[1024];
@@ -208,12 +213,6 @@
 	int	(*check)(int, const char *);	/* 1 if match, zero if not */
 	int	(*hide)(int, const char *);	/* non-zero if error */
 } exec_formats[] = {
-#ifdef NLIST_AOUT
-	{	"a.out",	check_aout,	hide_aout,	},
-#endif
-#ifdef NLIST_ECOFF
-	{	"ECOFF",	check_elf64,	hide_elf64,	},
-#endif
 #ifdef NLIST_ELF32
 	{	"ELF32",	check_elf32,	hide_elf32,	},
 #endif
@@ -222,7 +221,8 @@
 #endif
 };
 
-int hide_syms(const char *filename)
+int
+hide_syms(const char *filename)
 {
 	int fd, i, n, rv;
 

Modified: trunk/usr.sbin/crunch/crunchide/exec_elf32.c
===================================================================
--- trunk/usr.sbin/crunch/crunchide/exec_elf32.c	2018-06-10 20:23:48 UTC (rev 10823)
+++ trunk/usr.sbin/crunch/crunchide/exec_elf32.c	2018-06-10 20:25:03 UTC (rev 10824)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
  *
@@ -34,8 +35,8 @@
 __RCSID("$NetBSD: exec_elf32.c,v 1.6 1999/09/20 04:12:16 christos Exp $");
 #endif
 #endif
-__MBSDID("$MidnightBSD$");
- 
+__FBSDID("$FreeBSD: stable/10/usr.sbin/crunch/crunchide/exec_elf32.c 309077 2016-11-24 00:46:34Z emaste $");
+
 #ifndef ELFSIZE
 #define ELFSIZE         32
 #endif
@@ -46,6 +47,7 @@
 
 #include <errno.h>
 #include <limits.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -78,6 +80,9 @@
 #define ELFNAME2(x,y)   CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
 #define ELFNAMEEND(x)   CONCAT(x,CONCAT(_elf,ELFSIZE))
 #define ELFDEFNNAME(x)  CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
+#ifndef ELFCLASS
+#define ELFCLASS	CONCAT(ELFCLASS,ELFSIZE)
+#endif
 
 #define	xe16toh(x)	((data == ELFDATA2MSB) ? be16toh(x) : le16toh(x))
 #define	xe32toh(x)	((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x))
@@ -138,7 +143,7 @@
 xrealloc(void *ptr, size_t size, const char *fn, const char *use)
 {
 	void *rv;
-		
+
 	rv = realloc(ptr, size);
 	if (rv == NULL) {
 		free(ptr);
@@ -146,7 +151,7 @@
 		    fn, use);
 	}
 	return (rv);
-} 
+}
 
 int
 ELFNAMEEND(check)(int fd, const char *fn)
@@ -166,7 +171,7 @@
 	if (read(fd, &eh, sizeof eh) != sizeof eh)
 		return 0;
 
-	if (IS_ELF(eh) == 0)
+	if (IS_ELF(eh) == 0 || eh.e_ident[EI_CLASS] != ELFCLASS)
                 return 0;
 
 	data = eh.e_ident[EI_DATA];
@@ -174,37 +179,21 @@
 	switch (xe16toh(eh.e_machine)) {
 	case EM_386: break;
 	case EM_ALPHA: break;
-#ifndef EM_ARM
-#define EM_ARM		40
+#ifndef EM_AARCH64
+#define	EM_AARCH64	183
 #endif
+	case EM_AARCH64: break;
 	case EM_ARM: break;
-#ifndef EM_MIPS
-#define EM_MIPS		8
-#endif
-#ifndef EM_MIPS_RS4_BE		/* same as EM_MIPS_RS3_LE */
-#define EM_MIPS_RS4_BE	10
-#endif
+	case EM_IA_64: break;
 	case EM_MIPS: break;
 	case /* EM_MIPS_RS3_LE */ EM_MIPS_RS4_BE: break;
-#ifndef EM_IA_64
-#define	EM_IA_64	50
-#endif
-	case EM_IA_64: break;
-#ifndef EM_PPC
-#define	EM_PPC		20
-#endif
 	case EM_PPC: break;
-#ifndef EM_PPC64
-#define	EM_PPC64	21
-#endif
 	case EM_PPC64: break;
-#ifndef EM_SPARCV9
-#define	EM_SPARCV9	43
+#ifndef EM_RISCV
+#define	EM_RISCV	243
 #endif
+	case EM_RISCV: break;
 	case EM_SPARCV9: break;
-#ifndef EM_X86_64
-#define	EM_X86_64	62
-#endif
 	case EM_X86_64: break;
 /*        ELFDEFNNAME(MACHDEP_ID_CASES) */
 
@@ -292,6 +281,10 @@
 		weird = 1;
 		weirdreason = "section header string table does not exist";
 	}
+	if (strtabshdr == shstrtabshdr) {
+		weird = 1;
+		weirdreason = "combined strtab and shstrtab not supported";
+	}
 	if (weirdreason == NULL)
 		weirdreason = "unsupported";
 	if (weird) {
@@ -341,12 +334,15 @@
 	 */
 
 	/* load section string table for debug use */
-	if ((shstrtabp = xmalloc(xewtoh(shstrtabshdr->sh_size), fn,
-	    "section string table")) == NULL)
+	if ((size = xewtoh(shstrtabshdr->sh_size)) == 0)
 		goto bad;
+	if ((shstrtabp = xmalloc(size, fn, "section string table")) == NULL)
+		goto bad;
 	if ((size_t)xreadatoff(fd, shstrtabp, xewtoh(shstrtabshdr->sh_offset),
-	    xewtoh(shstrtabshdr->sh_size), fn) != xewtoh(shstrtabshdr->sh_size))
+	    size, fn) != size)
 		goto bad;
+	if (shstrtabp[size - 1] != '\0')
+		goto bad;
 
 	/* we need symtab, strtab, and everything behind strtab */
 	strtabidx = INT_MAX;
@@ -366,7 +362,8 @@
 			strtabidx = i;
 		if (layoutp[i].shdr == symtabshdr || i >= strtabidx) {
 			off = xewtoh(layoutp[i].shdr->sh_offset);
-			size = xewtoh(layoutp[i].shdr->sh_size);
+			if ((size = xewtoh(layoutp[i].shdr->sh_size)) == 0)
+				goto bad;
 			layoutp[i].bufp = xmalloc(size, fn,
 			    shstrtabp + xewtoh(layoutp[i].shdr->sh_name));
 			if (layoutp[i].bufp == NULL)
@@ -376,10 +373,13 @@
 				goto bad;
 
 			/* set symbol table and string table */
-			if (layoutp[i].shdr == symtabshdr)
+			if (layoutp[i].shdr == symtabshdr) {
 				symtabp = layoutp[i].bufp;
-			else if (layoutp[i].shdr == strtabshdr)
+			} else if (layoutp[i].shdr == strtabshdr) {
 				strtabp = layoutp[i].bufp;
+				if (strtabp[size - 1] != '\0')
+					goto bad;
+			}
 		}
 	}
 
@@ -464,7 +464,7 @@
 			if (layoutp[i].shdr == &shdrshdr &&
 			    ehdr.e_shoff != shdrshdr.sh_offset) {
 				ehdr.e_shoff = shdrshdr.sh_offset;
-				off = (ELFSIZE == 32) ? 32 : 44;
+				off = offsetof(Elf_Ehdr, e_shoff);
 				size = sizeof(Elf_Off);
 				if ((size_t)xwriteatoff(fd, &ehdr.e_shoff, off, size,
 				    fn) != size)

Modified: trunk/usr.sbin/crunch/crunchide/exec_elf64.c
===================================================================
--- trunk/usr.sbin/crunch/crunchide/exec_elf64.c	2018-06-10 20:23:48 UTC (rev 10823)
+++ trunk/usr.sbin/crunch/crunchide/exec_elf64.c	2018-06-10 20:25:03 UTC (rev 10824)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: exec_elf64.c,v 1.2 1997/08/02 21:30:19 perry Exp $	*/
 
 /*

Modified: trunk/usr.sbin/crunch/crunchide/extern.h
===================================================================
--- trunk/usr.sbin/crunch/crunchide/extern.h	2018-06-10 20:23:48 UTC (rev 10823)
+++ trunk/usr.sbin/crunch/crunchide/extern.h	2018-06-10 20:25:03 UTC (rev 10824)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: extern.h,v 1.5 1998/05/06 13:16:57 mycroft Exp $	*/
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/crunch/crunchide/extern.h 292422 2015-12-18 02:34:01Z emaste $ */
 
 /*
  * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
@@ -31,14 +32,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifdef NLIST_AOUT
-int	check_aout(int, const char *);
-int	hide_aout(int, const char *);
-#endif
-#ifdef NLIST_ECOFF
-int	check_ecoff(int, const char *);
-int	hide_ecoff(int, const char *);
-#endif
 #ifdef NLIST_ELF32
 int	check_elf32(int, const char *);
 int	hide_elf32(int, const char *);



More information about the Midnightbsd-cvs mailing list