diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-10-13 01:53:55 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-10-13 01:53:55 +0000 |
commit | 3aa3572daf58263aeba04de89f0a316cbdc36d54 (patch) | |
tree | 5da9503028c3687ce33f53e138780c02ca63a253 | |
parent | touchup output of TEXTREL matches and update the format help output (diff) | |
download | pax-utils-3aa3572daf58263aeba04de89f0a316cbdc36d54.tar.gz pax-utils-3aa3572daf58263aeba04de89f0a316cbdc36d54.tar.bz2 pax-utils-3aa3572daf58263aeba04de89f0a316cbdc36d54.zip |
split common non-elf features into paxinc.[ch]
-rw-r--r-- | Makefile | 40 | ||||
-rw-r--r-- | dumpelf.c | 6 | ||||
-rw-r--r-- | paxelf.c | 6 | ||||
-rw-r--r-- | paxelf.h | 44 | ||||
-rw-r--r-- | paxinc.c | 20 | ||||
-rw-r--r-- | paxinc.h | 68 | ||||
-rw-r--r-- | pspax.c | 4 | ||||
-rw-r--r-- | scanelf.c | 13 |
8 files changed, 120 insertions, 81 deletions
@@ -1,27 +1,12 @@ # Copyright 2003 Ned Ludd <solar@linbsd.net> # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/Makefile,v 1.38 2005/08/21 02:08:59 vapier Exp $ -#################################################################### -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, -# MA 02111-1307, USA. +# $Header: /var/cvsroot/gentoo-projects/pax-utils/Makefile,v 1.39 2005/10/13 01:53:55 vapier Exp $ #################################################################### check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \ then echo "$(1)"; else echo "$(2)"; fi) -#################################################### +#################################################################### WFLAGS := -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings \ -Wbad-function-cast -Wnested-externs -Wcomment -Winline \ @@ -43,11 +28,15 @@ ifdef PV HFLAGS += -DVERSION=\"$(PV)\" endif -##################################################### -TARGETS = scanelf pspax dumpelf -OBJS = ${TARGETS:%=%.o} paxelf.o -MPAGES = ${TARGETS:%=man/%.1} -SOURCES = ${OBJS:%.o=%.c} +#################################################################### +ELF_TARGETS = scanelf pspax dumpelf +ELF_OBJS = $(ELF_TARGETS:%=%.o) paxelf.o +#MACH_TARGETS = scanmacho +#MACH_OBJS = $(MACH_TARGETS:%=%.o) paxmacho.o +OBJS = $(ELF_OBJS) $(MACH_OBJS) paxinc.o +TARGETS = $(ELF_TARGETS) $(MACH_TARGETS) +MPAGES = $(TARGETS:%=man/%.1) +SOURCES = $(OBJS:%.o=%.c) all: $(OBJS) $(TARGETS) @: @@ -62,8 +51,11 @@ ifeq ($(subst s,,$(MAKEFLAGS)),$(MAKEFLAGS)) endif @$(CC) $(CFLAGS) $(WFLAGS) $(HFLAGS) -c $< -%: %.o paxelf.o - $(CC) $(CFLAGS) $(LDFLAGS) paxelf.o -o $@ $< +$(ELF_TARGETS): $(ELF_OBJS) paxinc.o + $(CC) $(CFLAGS) $(LDFLAGS) paxinc.o paxelf.o -o $@ $< + +$(MACH_TARGETS): $(MACH_OBJS) paxinc.o + $(CC) $(CFLAGS) $(LDFLAGS) paxinc.o paxmacho.o -o $@ $< %.so: %.c $(CC) -shared -fPIC -o $@ $< @@ -1,7 +1,7 @@ /* * Copyright 2005 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/dumpelf.c,v 1.12 2005/09/30 03:30:19 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/pax-utils/dumpelf.c,v 1.13 2005/10/13 01:53:55 vapier Exp $ * * Copyright 2005 Ned Ludd - <solar@gentoo.org> * Copyright 2005 Mike Frysinger - <vapier@gentoo.org> @@ -20,9 +20,9 @@ #include <assert.h> #include <ctype.h> -#include "paxelf.h" +#include "paxinc.h" -static const char *rcsid = "$Id: dumpelf.c,v 1.12 2005/09/30 03:30:19 vapier Exp $"; +static const char *rcsid = "$Id: dumpelf.c,v 1.13 2005/10/13 01:53:55 vapier Exp $"; #define argv0 "dumpelf" /* prototypes */ @@ -1,7 +1,7 @@ /* * Copyright 2003-2005 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxelf.c,v 1.28 2005/09/30 03:30:19 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxelf.c,v 1.29 2005/10/13 01:53:55 vapier Exp $ * * Copyright 2005 Ned Ludd - <solar@gentoo.org> * Copyright 2005 Mike Frysinger - <vapier@gentoo.org> @@ -13,12 +13,10 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> -#include "paxelf.h" +#include "paxinc.h" #define argv0 "paxelf" -char do_reverse_endian; - /* * Setup a bunch of helper functions to translate * binary defines into readable strings. @@ -1,7 +1,7 @@ /* * Copyright 2005 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxelf.h,v 1.35 2005/09/30 03:30:19 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxelf.h,v 1.36 2005/10/13 01:53:55 vapier Exp $ * * Copyright 2005 Ned Ludd - <solar@gentoo.org> * Copyright 2005 Mike Frysinger - <vapier@gentoo.org> @@ -12,29 +12,6 @@ #ifndef _PAX_ELF_H #define _PAX_ELF_H -#include "porting.h" - -#ifndef VERSION -# define VERSION "cvs" -#endif - -extern char do_reverse_endian; -/* Get a value 'X' in the elf header, compensating for endianness. */ -#define EGET(X) \ - (__extension__ ({ \ - uint64_t __res; \ - if (!do_reverse_endian) { __res = (X); \ - } else if (sizeof(X) == 1) { __res = (X); \ - } else if (sizeof(X) == 2) { __res = bswap_16((X)); \ - } else if (sizeof(X) == 4) { __res = bswap_32((X)); \ - } else if (sizeof(X) == 8) { __res = bswap_64((X)); \ - } else { \ - fprintf(stderr, "EGET failed ;(\n"); \ - exit(EXIT_FAILURE); \ - } \ - __res; \ - })) - typedef struct { void *ehdr; void *phdr; @@ -76,25 +53,6 @@ extern const char *get_elfshttype(int type); extern const char *get_elfstttype(int type); extern void *elf_findsecbyname(elfobj *elf, const char *name); -/* helper functions for showing errors */ -#define color 1 -#define COLOR(c,b) (color ? "\e[" c ";" b "m" : "") -#define NORM COLOR("00", "00") -#define RED COLOR("31", "01") -#define YELLOW COLOR("33", "01") - -/* we need the space before the last comma or we trigger a bug in gcc-2 :( */ -#define warn(fmt, args...) \ - fprintf(stderr, "%s%s%s: " fmt "\n", RED, argv0, NORM , ## args) -#define warnf(fmt, args...) warn("%s%s%s(): " fmt, YELLOW, __FUNCTION__, NORM , ## args) -#define _err(wfunc, fmt, args...) \ - do { \ - wfunc(fmt, ## args); \ - exit(EXIT_FAILURE); \ - } while (0) -#define err(fmt, args...) _err(warn, fmt, ## args) -#define errf(fmt, args...) _err(warnf, fmt, ## args) - /* PaX flags (to be read in elfhdr.e_flags) */ #define HF_PAX_PAGEEXEC 1 /* 0: Paging based non-exec pages */ #define HF_PAX_EMUTRAMP 2 /* 0: Emulate trampolines */ diff --git a/paxinc.c b/paxinc.c new file mode 100644 index 0000000..069814a --- /dev/null +++ b/paxinc.c @@ -0,0 +1,20 @@ +/* + * Copyright 2003-2005 Gentoo Foundation + * Distributed under the terms of the GNU General Public License v2 + * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.1 2005/10/13 01:53:55 vapier Exp $ + * + * Copyright 2005 Ned Ludd - <solar@gentoo.org> + * Copyright 2005 Mike Frysinger - <vapier@gentoo.org> + */ + +#include <stdio.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include "paxinc.h" + +#define argv0 "paxinc" + +char do_reverse_endian; diff --git a/paxinc.h b/paxinc.h new file mode 100644 index 0000000..953726c --- /dev/null +++ b/paxinc.h @@ -0,0 +1,68 @@ +/* + * Copyright 2005 Gentoo Foundation + * Distributed under the terms of the GNU General Public License v2 + * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.h,v 1.1 2005/10/13 01:53:55 vapier Exp $ + * + * Copyright 2005 Ned Ludd - <solar@gentoo.org> + * Copyright 2005 Mike Frysinger - <vapier@gentoo.org> + * + * Make sure all of the common stuff is setup as we expect + */ + +#ifndef _PAX_INC_H +#define _PAX_INC_H + +#include "porting.h" + +#ifndef VERSION +# define VERSION "cvs" +#endif + +/* ELF love */ +#include "elf.h" +#include "paxelf.h" + +/* MACH-O sucks */ +/* +#include "macho.h" +#include "paxmacho.h" +*/ + +extern char do_reverse_endian; + +/* Get a value 'X', compensating for endianness. */ +#define EGET(X) \ + (__extension__ ({ \ + uint64_t __res; \ + if (!do_reverse_endian) { __res = (X); \ + } else if (sizeof(X) == 1) { __res = (X); \ + } else if (sizeof(X) == 2) { __res = bswap_16((X)); \ + } else if (sizeof(X) == 4) { __res = bswap_32((X)); \ + } else if (sizeof(X) == 8) { __res = bswap_64((X)); \ + } else { \ + fprintf(stderr, "EGET failed ;(\n"); \ + exit(EXIT_FAILURE); \ + } \ + __res; \ + })) + +/* helper functions for showing errors */ +#define color 1 +#define COLOR(c,b) (color ? "\e[" c ";" b "m" : "") +#define NORM COLOR("00", "00") +#define RED COLOR("31", "01") +#define YELLOW COLOR("33", "01") + +/* we need the space before the last comma or we trigger a bug in gcc-2 :( */ +#define warn(fmt, args...) \ + fprintf(stderr, "%s%s%s: " fmt "\n", RED, argv0, NORM , ## args) +#define warnf(fmt, args...) warn("%s%s%s(): " fmt, YELLOW, __FUNCTION__, NORM , ## args) +#define _err(wfunc, fmt, args...) \ + do { \ + wfunc(fmt, ## args); \ + exit(EXIT_FAILURE); \ + } while (0) +#define err(fmt, args...) _err(warn, fmt, ## args) +#define errf(fmt, args...) _err(warnf, fmt, ## args) + +#endif /* _PAX_INC_H */ @@ -32,7 +32,7 @@ #include <fcntl.h> #include <getopt.h> -#include "paxelf.h" +#include "paxinc.h" #ifdef WANT_SYSCAP #undef _POSIX_SOURCE @@ -40,7 +40,7 @@ #endif #define PROC_DIR "/proc" -static const char *rcsid = "$Id: pspax.c,v 1.22 2005/07/03 16:17:23 solar Exp $"; +static const char *rcsid = "$Id: pspax.c,v 1.23 2005/10/13 01:53:55 vapier Exp $"; #define argv0 "pspax" @@ -1,7 +1,7 @@ /* * Copyright 2003-2005 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.88 2005/09/30 03:30:54 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.89 2005/10/13 01:53:55 vapier Exp $ * * Copyright 2003-2005 Ned Ludd - <solar@gentoo.org> * Copyright 2004-2005 Mike Frysinger - <vapier@gentoo.org> @@ -20,9 +20,9 @@ #include <dirent.h> #include <getopt.h> #include <assert.h> -#include "paxelf.h" +#include "paxinc.h" -static const char *rcsid = "$Id: scanelf.c,v 1.88 2005/09/30 03:30:54 vapier Exp $"; +static const char *rcsid = "$Id: scanelf.c,v 1.89 2005/10/13 01:53:55 vapier Exp $"; #define argv0 "scanelf" #define IS_MODIFIER(c) (c == '%' || c == '#') @@ -339,10 +339,13 @@ static void rpath_security_checks(elfobj *, char *); static void rpath_security_checks(elfobj *elf, char *item) { struct stat st; switch (*item) { - case 0: + case '/': break; + case '.': + warnf("Security problem with relative RPATH '%s' in %s", item, elf->filename); + break; + case '\0': warnf("Security problem NULL RPATH in %s", elf->filename); break; - case '/': break; case '$': if (fstat(elf->fd, &st) != -1) if ((st.st_mode & S_ISUID) || (st.st_mode & S_ISGID)) |