Use xmalloc and read(2) instead of mmap(2) to read in libmap.conf(5).

This removes the need to call munmap(2) afterwards.

MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D12767
This commit is contained in:
trasz 2017-10-24 10:48:26 +00:00
parent 7059976537
commit f80b548569

View File

@ -100,6 +100,7 @@ lmc_parse_file(char *path)
{
struct lmc *p;
struct stat st;
ssize_t retval;
int fd;
char *lm_map;
@ -128,10 +129,11 @@ lmc_parse_file(char *path)
}
}
lm_map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (lm_map == (const char *)MAP_FAILED) {
lm_map = xmalloc(st.st_size);
retval = read(fd, lm_map, st.st_size);
if (retval != st.st_size) {
close(fd);
dbg("lm_parse_file: mmap(\"%s\") failed, %s", path,
dbg("lm_parse_file: read(\"%s\") failed, %s", path,
rtld_strerror(errno));
return;
}
@ -142,7 +144,7 @@ lmc_parse_file(char *path)
p->ino = st.st_ino;
TAILQ_INSERT_HEAD(&lmc_head, p, next);
lmc_parse(lm_map, st.st_size);
munmap(lm_map, st.st_size);
free(lm_map);
}
static void