summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2017-12-03 19:32:20 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2017-12-03 19:32:20 +0000
commit83e5cb6e1ff93a4b130345b1a965e8126604fab8 (patch)
treeb2385b18f806499a01f36896f699dfc8bf68fee4
parent2286df923da16c107a4317f215cf3eb6fd0289ab (diff)
pledge(2) elfrdsetroot:
- pledge(2) "stdio" after managing arguments (opening files) - add $OpenBSD$ markers on elfrd_size.c and elfrdsetroot.h - add a check for NULL on malloc(3) call in elfrd_size.c from semarie, ok deraadt
-rw-r--r--distrib/common/elfrd_size.c8
-rw-r--r--distrib/common/elfrdsetroot.c7
-rw-r--r--distrib/common/elfrdsetroot.h2
3 files changed, 14 insertions, 3 deletions
diff --git a/distrib/common/elfrd_size.c b/distrib/common/elfrd_size.c
index 60bb1807585..d53442b69ff 100644
--- a/distrib/common/elfrd_size.c
+++ b/distrib/common/elfrd_size.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: elfrd_size.c,v 1.8 2017/12/03 19:32:19 tb Exp $ */
+
#include <sys/types.h>
#include <sys/file.h>
#include <sys/mman.h>
@@ -52,8 +54,10 @@ ELFNAME(locate_image)(int fd, struct elfhdr *ghead, char *file,
}
phsize = head.e_phnum * sizeof(Elf_Phdr);
- ph = malloc(phsize);
-
+ if ((ph = malloc(phsize)) == NULL) {
+ perror("malloc");
+ exit(1);
+ }
lseek(fd, head.e_phoff, SEEK_SET);
diff --git a/distrib/common/elfrdsetroot.c b/distrib/common/elfrdsetroot.c
index 71bd893ee36..905047ba6db 100644
--- a/distrib/common/elfrdsetroot.c
+++ b/distrib/common/elfrdsetroot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: elfrdsetroot.c,v 1.24 2017/10/29 08:45:53 mpi Exp $ */
+/* $OpenBSD: elfrdsetroot.c,v 1.25 2017/12/03 19:32:19 tb Exp $ */
/* $NetBSD: rdsetroot.c,v 1.2 1995/10/13 16:38:39 gwr Exp $ */
/*
@@ -121,6 +121,11 @@ main(int argc, char *argv[])
exit(1);
}
+ if (pledge("stdio", NULL) == -1) {
+ perror("pledge");
+ exit(1);
+ }
+
n = read(fd, &head, sizeof(head));
if (n < sizeof(head)) {
fprintf(stderr, "%s: reading header\n", file);
diff --git a/distrib/common/elfrdsetroot.h b/distrib/common/elfrdsetroot.h
index 7e806dcd950..e32391aaadc 100644
--- a/distrib/common/elfrdsetroot.h
+++ b/distrib/common/elfrdsetroot.h
@@ -1,3 +1,5 @@
+/* $OpenBSD: elfrdsetroot.h,v 1.3 2017/12/03 19:32:19 tb Exp $ */
+
struct elf_fn {
void (*locate_image)(int, struct elfhdr *, char *, long *, long *,
off_t *, size_t *);