aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-10-13 01:53:55 +0000
committerMike Frysinger <vapier@gentoo.org>2005-10-13 01:53:55 +0000
commit3aa3572daf58263aeba04de89f0a316cbdc36d54 (patch)
tree5da9503028c3687ce33f53e138780c02ca63a253
parenttouchup output of TEXTREL matches and update the format help output (diff)
downloadpax-utils-3aa3572daf58263aeba04de89f0a316cbdc36d54.tar.gz
pax-utils-3aa3572daf58263aeba04de89f0a316cbdc36d54.tar.bz2
pax-utils-3aa3572daf58263aeba04de89f0a316cbdc36d54.zip
split common non-elf features into paxinc.[ch]
-rw-r--r--Makefile40
-rw-r--r--dumpelf.c6
-rw-r--r--paxelf.c6
-rw-r--r--paxelf.h44
-rw-r--r--paxinc.c20
-rw-r--r--paxinc.h68
-rw-r--r--pspax.c4
-rw-r--r--scanelf.c13
8 files changed, 120 insertions, 81 deletions
diff --git a/Makefile b/Makefile
index 6112f64..feb3c00 100644
--- a/Makefile
+++ b/Makefile
@@ -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 $@ $<
diff --git a/dumpelf.c b/dumpelf.c
index 794f8ba..a0750fc 100644
--- a/dumpelf.c
+++ b/dumpelf.c
@@ -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 */
diff --git a/paxelf.c b/paxelf.c
index 26fb924..27f62e8 100644
--- a/paxelf.c
+++ b/paxelf.c
@@ -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.
diff --git a/paxelf.h b/paxelf.h
index fb277b8..04577b0 100644
--- a/paxelf.h
+++ b/paxelf.h
@@ -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 */
diff --git a/pspax.c b/pspax.c
index 9e869c0..7475ab7 100644
--- a/pspax.c
+++ b/pspax.c
@@ -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"
diff --git a/scanelf.c b/scanelf.c
index 5d027c7..aeba2c0 100644
--- a/scanelf.c
+++ b/scanelf.c
@@ -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))