Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/acpitools/amldb mmap MAP_FAILED audit.



details:   https://anonhg.NetBSD.org/src/rev/b56993822c36
branches:  trunk
changeset: 942802:b56993822c36
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Aug 20 15:54:11 2020 +0000

description:
mmap MAP_FAILED audit.

diffstat:

 external/bsd/ppp/usr.sbin/pppd/tdb.c                 |  6 ++++++
 external/bsd/tre/dist/src/agrep.c                    |  4 ++++
 external/cddl/osnet/dist/cmd/ztest/ztest.c           |  6 +++---
 external/cddl/osnet/dist/common/ctf/ctf_open.c       |  6 +++---
 external/cddl/osnet/dist/lib/libctf/common/ctf_lib.c |  3 +++
 lib/libc/tls/tls.c                                   |  6 ++++--
 sbin/newfs/mkfs.c                                    |  7 ++++---
 sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c       |  4 ++--
 usr.sbin/acpitools/acpidump/acpi_user.c              |  6 +++---
 usr.sbin/acpitools/amldb/amldb.c                     |  7 ++++---
 10 files changed, 36 insertions(+), 19 deletions(-)

diffs (244 lines):

diff -r 783f05a6ebed -r b56993822c36 external/bsd/ppp/usr.sbin/pppd/tdb.c
--- a/external/bsd/ppp/usr.sbin/pppd/tdb.c      Thu Aug 20 13:58:30 2020 +0000
+++ b/external/bsd/ppp/usr.sbin/pppd/tdb.c      Thu Aug 20 15:54:11 2020 +0000
@@ -222,6 +222,8 @@
        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 @@
             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.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
 
diff -r 783f05a6ebed -r b56993822c36 external/bsd/tre/dist/src/agrep.c
--- a/external/bsd/tre/dist/src/agrep.c Thu Aug 20 13:58:30 2020 +0000
+++ b/external/bsd/tre/dist/src/agrep.c Thu Aug 20 15:54:11 2020 +0000
@@ -336,6 +336,10 @@
        } 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;
diff -r 783f05a6ebed -r b56993822c36 external/cddl/osnet/dist/cmd/ztest/ztest.c
--- a/external/cddl/osnet/dist/cmd/ztest/ztest.c        Thu Aug 20 13:58:30 2020 +0000
+++ b/external/cddl/osnet/dist/cmd/ztest/ztest.c        Thu Aug 20 15:54:11 2020 +0000
@@ -6034,7 +6034,7 @@
 
        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 @@
 
        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;
diff -r 783f05a6ebed -r b56993822c36 external/cddl/osnet/dist/common/ctf/ctf_open.c
--- a/external/cddl/osnet/dist/common/ctf/ctf_open.c    Thu Aug 20 13:58:30 2020 +0000
+++ b/external/cddl/osnet/dist/common/ctf/ctf_open.c    Thu Aug 20 15:54:11 2020 +0000
@@ -814,7 +814,7 @@
         */
        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 @@
        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 @@
        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;
                }
diff -r 783f05a6ebed -r b56993822c36 external/cddl/osnet/dist/lib/libctf/common/ctf_lib.c
--- a/external/cddl/osnet/dist/lib/libctf/common/ctf_lib.c      Thu Aug 20 13:58:30 2020 +0000
+++ b/external/cddl/osnet/dist/lib/libctf/common/ctf_lib.c      Thu Aug 20 15:54:11 2020 +0000
@@ -374,6 +374,9 @@
                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);
 
diff -r 783f05a6ebed -r b56993822c36 lib/libc/tls/tls.c
--- a/lib/libc/tls/tls.c        Thu Aug 20 13:58:30 2020 +0000
+++ b/lib/libc/tls/tls.c        Thu Aug 20 15:54:11 2020 +0000
@@ -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 @@
                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));
        }
diff -r 783f05a6ebed -r b56993822c36 sbin/newfs/mkfs.c
--- a/sbin/newfs/mkfs.c Thu Aug 20 13:58:30 2020 +0000
+++ b/sbin/newfs/mkfs.c Thu Aug 20 15:54:11 2020 +0000
@@ -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 @@
        /* 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) {
diff -r 783f05a6ebed -r b56993822c36 sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c
--- a/sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c    Thu Aug 20 13:58:30 2020 +0000
+++ b/sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c    Thu Aug 20 15:54:11 2020 +0000
@@ -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 @@
                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 */
diff -r 783f05a6ebed -r b56993822c36 usr.sbin/acpitools/acpidump/acpi_user.c
--- a/usr.sbin/acpitools/acpidump/acpi_user.c   Thu Aug 20 13:58:30 2020 +0000
+++ b/usr.sbin/acpitools/acpidump/acpi_user.c   Thu Aug 20 15:54:11 2020 +0000
@@ -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 @@
                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;
diff -r 783f05a6ebed -r b56993822c36 usr.sbin/acpitools/amldb/amldb.c
--- a/usr.sbin/acpitools/amldb/amldb.c  Thu Aug 20 13:58:30 2020 +0000
+++ b/usr.sbin/acpitools/amldb/amldb.c  Thu Aug 20 15:54:11 2020 +0000
@@ -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@localhost>
@@ -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 @@
                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);
        }



Home | Main Index | Thread Index | Old Index