summaryrefslogtreecommitdiffstats
path: root/usr.bin/gcore
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>1998-10-14 16:16:50 +0000
committerjdp <jdp@FreeBSD.org>1998-10-14 16:16:50 +0000
commitf417a55b2f876ac7d08c9191e450e257179228c4 (patch)
tree449731286a37b58424be9bb859f6c77e7bd0793e /usr.bin/gcore
parent1f69c742ab24044ec9addb4057e26f4e68ae479f (diff)
downloadFreeBSD-src-f417a55b2f876ac7d08c9191e450e257179228c4.zip
FreeBSD-src-f417a55b2f876ac7d08c9191e450e257179228c4.tar.gz
Check the executable's header to make sure it is a valid executable.
If it is ELF, print a diagnostic saying that it is not supported yet by this program. This is a stop-gap anti-bug-report measure because it looks like there won't be time to implement gcore's ELF support before 3.0 is released.
Diffstat (limited to 'usr.bin/gcore')
-rw-r--r--usr.bin/gcore/aoutcore.c10
-rw-r--r--usr.bin/gcore/gcore.c10
2 files changed, 18 insertions, 2 deletions
diff --git a/usr.bin/gcore/aoutcore.c b/usr.bin/gcore/aoutcore.c
index a943a30..8ab7b0b 100644
--- a/usr.bin/gcore/aoutcore.c
+++ b/usr.bin/gcore/aoutcore.c
@@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)gcore.c 8.2 (Berkeley) 9/23/93";
#endif
static const char rcsid[] =
- "$Id: gcore.c,v 1.8 1998/08/24 16:25:30 wosch Exp $";
+ "$Id: gcore.c,v 1.9 1998/09/14 10:09:30 des Exp $";
#endif /* not lint */
/*
@@ -66,6 +66,7 @@ static const char rcsid[] =
#include <machine/vmparam.h>
#include <a.out.h>
+#include <elf.h>
#include <err.h>
#include <fcntl.h>
#include <kvm.h>
@@ -174,6 +175,13 @@ main(argc, argv)
if (cnt != sizeof(exec))
errx(1, "%s exec header: %s",
binfile, cnt > 0 ? strerror(EIO) : strerror(errno));
+ if (N_BADMAG(exec)) {
+ const Elf_Ehdr *ehdr = (const Elf_Ehdr *)&exec;
+
+ if (IS_ELF(*ehdr))
+ errx(1, "ELF executables are not supported yet");
+ errx(1, "Invalid executable file");
+ }
/* check the text segment size of the executable and the process */
if (exec.a_text != ptoa(ki->kp_eproc.e_vm.vm_tsize))
diff --git a/usr.bin/gcore/gcore.c b/usr.bin/gcore/gcore.c
index a943a30..8ab7b0b 100644
--- a/usr.bin/gcore/gcore.c
+++ b/usr.bin/gcore/gcore.c
@@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)gcore.c 8.2 (Berkeley) 9/23/93";
#endif
static const char rcsid[] =
- "$Id: gcore.c,v 1.8 1998/08/24 16:25:30 wosch Exp $";
+ "$Id: gcore.c,v 1.9 1998/09/14 10:09:30 des Exp $";
#endif /* not lint */
/*
@@ -66,6 +66,7 @@ static const char rcsid[] =
#include <machine/vmparam.h>
#include <a.out.h>
+#include <elf.h>
#include <err.h>
#include <fcntl.h>
#include <kvm.h>
@@ -174,6 +175,13 @@ main(argc, argv)
if (cnt != sizeof(exec))
errx(1, "%s exec header: %s",
binfile, cnt > 0 ? strerror(EIO) : strerror(errno));
+ if (N_BADMAG(exec)) {
+ const Elf_Ehdr *ehdr = (const Elf_Ehdr *)&exec;
+
+ if (IS_ELF(*ehdr))
+ errx(1, "ELF executables are not supported yet");
+ errx(1, "Invalid executable file");
+ }
/* check the text segment size of the executable and the process */
if (exec.a_text != ptoa(ki->kp_eproc.e_vm.vm_tsize))
OpenPOWER on IntegriCloud