From 515b79ed7882e78ae39228f32b2c4fc02506eaf3 Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 3 Dec 2017 19:32:19 +0000 Subject: [PATCH] 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 --- distrib/common/elfrd_size.c | 8 ++++++-- distrib/common/elfrdsetroot.c | 7 ++++++- distrib/common/elfrdsetroot.h | 2 ++ 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 #include #include @@ -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 *); -- 2.20.1