mmap MAP_FAILED audit.
This commit is contained in:
parent
f1323c812d
commit
25f11de3b9
|
@ -222,6 +222,8 @@ static int tdb_oob(TDB_CONTEXT *tdb, tdb_off offset)
|
|||
tdb->map_ptr = (void *)mmap(NULL, tdb->map_size,
|
||||
tdb->read_only?PROT_READ:PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED | MAP_FILE, tdb->fd, 0);
|
||||
if (tdb->map_ptr == MAP_FAILED)
|
||||
tdb->map_ptr = NULL;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -389,6 +391,8 @@ static int tdb_expand(TDB_CONTEXT *tdb, tdb_off length)
|
|||
tdb->map_ptr = (void *)mmap(NULL, tdb->map_size,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED | MAP_FILE, tdb->fd, 0);
|
||||
if (tdb->map_ptr == MAP_FAILED)
|
||||
tdb->map_ptr = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1194,6 +1198,8 @@ TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags,
|
|||
tdb.map_ptr = (void *)mmap(NULL, st.st_size,
|
||||
tdb.read_only? PROT_READ : PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED | MAP_FILE, tdb.fd, 0);
|
||||
if (tdb->map_ptr == MAP_FAILED)
|
||||
tdb->map_ptr = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -336,6 +336,10 @@ isbinaryfile(const char *filename)
|
|||
} else {
|
||||
size = (size_t)st.st_size;
|
||||
mapped = mmap(NULL, size, PROT_READ, MAP_SHARED, fileno(fp), 0);
|
||||
if (mapped == MAP_FAILED) {
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
for (i = 0 ; !isbin && i < size ; i++) {
|
||||
if (mapped[i] == 0x0) {
|
||||
isbin = 1;
|
||||
|
|
|
@ -6034,7 +6034,7 @@ setup_hdr(void)
|
|||
|
||||
hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, ztest_fd_data, 0);
|
||||
ASSERT(hdr != MAP_FAILED);
|
||||
VERIFY(hdr != MAP_FAILED);
|
||||
|
||||
VERIFY3U(0, ==, ftruncate(ztest_fd_data, sizeof (ztest_shared_hdr_t)));
|
||||
|
||||
|
@ -6061,14 +6061,14 @@ setup_data(void)
|
|||
|
||||
hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
|
||||
PROT_READ, MAP_SHARED, ztest_fd_data, 0);
|
||||
ASSERT(hdr != MAP_FAILED);
|
||||
VERIFY(hdr != MAP_FAILED);
|
||||
|
||||
size = shared_data_size(hdr);
|
||||
|
||||
(void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
|
||||
hdr = ztest_shared_hdr = (void *)mmap(0, P2ROUNDUP(size, getpagesize()),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, ztest_fd_data, 0);
|
||||
ASSERT(hdr != MAP_FAILED);
|
||||
VERIFY(hdr != MAP_FAILED);
|
||||
buf = (uint8_t *)hdr;
|
||||
|
||||
offset = hdr->zh_hdr_size;
|
||||
|
|
|
@ -814,7 +814,7 @@ ctf_dup(ctf_file_t *ofp)
|
|||
*/
|
||||
bcopy(&ofp->ctf_data, &ctfsect, sizeof (ctf_sect_t));
|
||||
cbuf = ctf_data_alloc(ctfsect.cts_size);
|
||||
if (cbuf == NULL) {
|
||||
if (cbuf == MAP_FAILED) {
|
||||
(void) ctf_set_errno(ofp, ECTF_MMAP);
|
||||
return (NULL);
|
||||
}
|
||||
|
@ -828,7 +828,7 @@ ctf_dup(ctf_file_t *ofp)
|
|||
if (ofp->ctf_symtab.cts_data != NULL) {
|
||||
bcopy(&ofp->ctf_symtab, &symsect, sizeof (ctf_sect_t));
|
||||
symbuf = ctf_data_alloc(symsect.cts_size);
|
||||
if (symbuf == NULL) {
|
||||
if (symbuf == MAP_FAILED) {
|
||||
(void) ctf_set_errno(ofp, ECTF_MMAP);
|
||||
goto err;
|
||||
}
|
||||
|
@ -844,7 +844,7 @@ ctf_dup(ctf_file_t *ofp)
|
|||
if (ofp->ctf_strtab.cts_data != NULL) {
|
||||
bcopy(&ofp->ctf_strtab, &strsect, sizeof (ctf_sect_t));
|
||||
strbuf = ctf_data_alloc(strsect.cts_size);
|
||||
if (strbuf == NULL) {
|
||||
if (strbuf == MAP_FAILED) {
|
||||
(void) ctf_set_errno(ofp, ECTF_MMAP);
|
||||
goto err;
|
||||
}
|
||||
|
|
|
@ -374,6 +374,9 @@ ctf_fdopen(int fd, int *errp)
|
|||
strs_map = mmap64(NULL, strs_mapsz, PROT_READ, MAP_PRIVATE,
|
||||
fd, sp[shstrndx].sh_offset & _PAGEMASK);
|
||||
|
||||
if (strs_map == MAP_FAILED)
|
||||
return (ctf_set_open_errno(errp, errno));
|
||||
|
||||
strs = (char *)strs_map +
|
||||
(sp[shstrndx].sh_offset & ~_PAGEMASK);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tls.c,v 1.13 2019/11/21 23:06:15 nakayama Exp $ */
|
||||
/* $NetBSD: tls.c,v 1.14 2020/08/20 15:54:11 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: tls.c,v 1.13 2019/11/21 23:06:15 nakayama Exp $");
|
||||
__RCSID("$NetBSD: tls.c,v 1.14 2020/08/20 15:54:11 riastradh Exp $");
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
|
@ -94,6 +94,8 @@ _rtld_tls_allocate(void)
|
|||
initial_thread_tcb = p = mmap(NULL,
|
||||
tls_allocation + sizeof(*tcb), PROT_READ | PROT_WRITE,
|
||||
MAP_ANON, -1, 0);
|
||||
if (p == MAP_FAILED)
|
||||
initial_thread_tcb = p = NULL;
|
||||
} else {
|
||||
p = calloc(1, tls_allocation + sizeof(*tcb));
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mkfs.c,v 1.129 2020/04/17 09:33:37 jdolecek Exp $ */
|
||||
/* $NetBSD: mkfs.c,v 1.130 2020/08/20 15:54:11 riastradh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1989, 1993
|
||||
|
@ -73,7 +73,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: mkfs.c,v 1.129 2020/04/17 09:33:37 jdolecek Exp $");
|
||||
__RCSID("$NetBSD: mkfs.c,v 1.130 2020/08/20 15:54:11 riastradh Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -1668,7 +1668,8 @@ mkfs_malloc(size_t size)
|
|||
/* try to map something extra */
|
||||
extra = mmap(0, exsize, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE,
|
||||
-1, 0);
|
||||
munmap(extra, exsize);
|
||||
if (extra != MAP_FAILED)
|
||||
munmap(extra, exsize);
|
||||
|
||||
/* if extra memory couldn't be mapped, reduce original request accordingly */
|
||||
if (extra == MAP_FAILED) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: elf2bb.c,v 1.16 2011/07/11 01:24:34 mrg Exp $ */
|
||||
/* $NetBSD: elf2bb.c,v 1.17 2020/08/20 15:54:12 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996,2006 The NetBSD Foundation, Inc.
|
||||
|
@ -141,7 +141,7 @@ main(int argc, char *argv[])
|
|||
err(1, "Can't open %s", argv[0]);
|
||||
|
||||
image = mmap(0, 65536, PROT_READ, MAP_FILE|MAP_PRIVATE, ifd, 0);
|
||||
if (image == 0)
|
||||
if (image == MAP_FAILED)
|
||||
err(1, "Can't mmap %s", argv[1]);
|
||||
|
||||
eh = (Elf32_Ehdr *)image; /* XXX endianness */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: acpi_user.c,v 1.4 2017/08/04 06:30:36 msaitoh Exp $ */
|
||||
/* $NetBSD: acpi_user.c,v 1.5 2020/08/20 15:54:12 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 Doug Rabson
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: acpi_user.c,v 1.4 2017/08/04 06:30:36 msaitoh Exp $");
|
||||
__RCSID("$NetBSD: acpi_user.c,v 1.5 2020/08/20 15:54:12 riastradh Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -204,7 +204,7 @@ dsdt_load_file(char *infile)
|
|||
errx(EXIT_FAILURE, "fstat %s", infile);
|
||||
|
||||
dp = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, acpi_mem_fd, 0);
|
||||
if (dp == NULL)
|
||||
if (dp == MAP_FAILED)
|
||||
errx(EXIT_FAILURE, "mmap %s", infile);
|
||||
|
||||
sdt = (ACPI_TABLE_HEADER *)dp;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: amldb.c,v 1.4 2018/10/14 12:43:58 jmcneill Exp $ */
|
||||
/* $NetBSD: amldb.c,v 1.5 2020/08/20 15:54:12 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
|
||||
|
@ -29,7 +29,7 @@
|
|||
* $FreeBSD: src/usr.sbin/acpi/amldb/amldb.c,v 1.3 2001/10/22 17:25:32 iwasaki Exp $
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: amldb.c,v 1.4 2018/10/14 12:43:58 jmcneill Exp $");
|
||||
__RCSID("$NetBSD: amldb.c,v 1.5 2020/08/20 15:54:12 riastradh Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -91,7 +91,8 @@ load_dsdt(const char *dsdtfile)
|
|||
perror("fstat");
|
||||
exit(-1);
|
||||
}
|
||||
if ((code = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == NULL) {
|
||||
if ((code = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) ==
|
||||
MAP_FAILED) {
|
||||
perror("mmap");
|
||||
exit(-1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue