aboutsummaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorGlen Barber <gjb@FreeBSD.org>2016-02-02 22:27:48 +0000
committerGlen Barber <gjb@FreeBSD.org>2016-02-02 22:27:48 +0000
commit221b3499126e3891b22e08cd6b5d3866c26ef900 (patch)
tree5ea64f05cc16d8a5032524fdefec823e707e1ff3 /libexec
parent43faedc1339a9624c7acedb7f3e5624e64da5b99 (diff)
parent6350eae8e458637096ee44d0968961cfa4c41810 (diff)
downloadsrc-221b3499126e3891b22e08cd6b5d3866c26ef900.tar.gz
src-221b3499126e3891b22e08cd6b5d3866c26ef900.zip
Notes
Diffstat (limited to 'libexec')
-rw-r--r--libexec/atrun/atrun.c3
-rw-r--r--libexec/rtld-elf/map_object.c12
2 files changed, 11 insertions, 4 deletions
diff --git a/libexec/atrun/atrun.c b/libexec/atrun/atrun.c
index 1e25766c41b1..7b11e7bb1997 100644
--- a/libexec/atrun/atrun.c
+++ b/libexec/atrun/atrun.c
@@ -459,8 +459,9 @@ main(int argc, char *argv[])
int c;
int run_batch;
#ifdef __FreeBSD__
- size_t ncpu, ncpusz;
+ size_t ncpusz;
double load_avg = -1;
+ int ncpu;
#else
double load_avg = LOADAVG_MX;
#endif
diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c
index 6012015bcc28..f4f6f4221816 100644
--- a/libexec/rtld-elf/map_object.c
+++ b/libexec/rtld-elf/map_object.c
@@ -38,7 +38,7 @@
#include "debug.h"
#include "rtld.h"
-static Elf_Ehdr *get_elf_header(int, const char *);
+static Elf_Ehdr *get_elf_header(int, const char *, const struct stat *);
static int convert_prot(int); /* Elf flags -> mmap protection */
static int convert_flags(int); /* Elf flags -> mmap flags */
@@ -91,7 +91,7 @@ map_object(int fd, const char *path, const struct stat *sb)
char *note_map;
size_t note_map_len;
- hdr = get_elf_header(fd, path);
+ hdr = get_elf_header(fd, path, sb);
if (hdr == NULL)
return (NULL);
@@ -324,10 +324,16 @@ error:
}
static Elf_Ehdr *
-get_elf_header(int fd, const char *path)
+get_elf_header(int fd, const char *path, const struct stat *sbp)
{
Elf_Ehdr *hdr;
+ /* Make sure file has enough data for the ELF header */
+ if (sbp != NULL && sbp->st_size < sizeof(Elf_Ehdr)) {
+ _rtld_error("%s: invalid file format", path);
+ return (NULL);
+ }
+
hdr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_PREFAULT_READ,
fd, 0);
if (hdr == (Elf_Ehdr *)MAP_FAILED) {