Hi,
elfrdsetroot is a small tool living in src/distrib/common/ and used when
generating bsd.rd to put a ffs image inside RAMDISK kernel.
The diff does the following:
- pledge(2) it with only "stdio" just after managed arguments (opening files)
- add $OpenBSD$ marker on elfrd_size.c (no one present)
- add a check for NULL on malloc(3) call in elfrd_size.c
As there is no Makefile in the directory, in order to test it you should
compile it with:
$ cc -o elfrdsetroot elfrdsetroot.c elf32.c elf64.c
$ ./elfrdsetroot
usage: elfrdsetroot [-dx] bsd [fs]
or just create a Makefile this one:
$ cat Makefile
# $OpenBSD$
PROG = elfrdsetroot
SRCS = elfrdsetroot.c elf64.c elf32.c
NOMAN = elfrdsetroot.1
.include <bsd.prog.mk>
Thanks.
--
Sebastien Marie
Index: distrib/common/elfrd_size.c
===================================================================
RCS file: /cvs/src/distrib/common/elfrd_size.c,v
retrieving revision 1.7
diff -u -p -r1.7 elfrd_size.c
--- distrib/common/elfrd_size.c 29 Oct 2017 08:45:53 -0000 1.7
+++ distrib/common/elfrd_size.c 3 Dec 2017 09:19:15 -0000
@@ -1,3 +1,4 @@
+/* $OpenBSD$ */
#include <sys/types.h>
#include <sys/file.h>
#include <sys/mman.h>
@@ -52,8 +53,10 @@ ELFNAME(locate_image)(int fd, struct elf
}
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);
Index: distrib/common/elfrdsetroot.c
===================================================================
RCS file: /cvs/src/distrib/common/elfrdsetroot.c,v
retrieving revision 1.24
diff -u -p -r1.24 elfrdsetroot.c
--- distrib/common/elfrdsetroot.c 29 Oct 2017 08:45:53 -0000 1.24
+++ distrib/common/elfrdsetroot.c 3 Dec 2017 09:19:15 -0000
@@ -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);