Source-Changes-HG archive

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

[src/trunk]: src/sys/miscfs/procfs Instead of casting to size_t, cast to uint...



details:   https://anonhg.NetBSD.org/src/rev/e6b858ea57f9
branches:  trunk
changeset: 965694:e6b858ea57f9
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Sep 27 14:36:18 2019 +0000

description:
Instead of casting to size_t, cast to uintmax_t to prevent truncation
(pointed out by chuq). In all these cases uio_offset can't be negative.

diffstat:

 sys/miscfs/procfs/procfs_auxv.c    |   6 +++---
 sys/miscfs/procfs/procfs_cmdline.c |  10 +++++-----
 sys/miscfs/procfs/procfs_limit.c   |   6 +++---
 sys/miscfs/procfs/procfs_map.c     |   6 +++---
 4 files changed, 14 insertions(+), 14 deletions(-)

diffs (124 lines):

diff -r c311a579d830 -r e6b858ea57f9 sys/miscfs/procfs/procfs_auxv.c
--- a/sys/miscfs/procfs/procfs_auxv.c   Fri Sep 27 12:58:54 2019 +0000
+++ b/sys/miscfs/procfs/procfs_auxv.c   Fri Sep 27 14:36:18 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_auxv.c,v 1.3 2019/09/26 17:34:08 christos Exp $ */
+/*     $NetBSD: procfs_auxv.c,v 1.4 2019/09/27 14:36:18 christos Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_auxv.c,v 1.3 2019/09/26 17:34:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_auxv.c,v 1.4 2019/09/27 14:36:18 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -52,7 +52,7 @@
        if ((error = proc_getauxv(p, &buffer, &bufsize)) != 0)
                return error;
 
-       if ((size_t)uio->uio_offset < bufsize)
+       if ((uintmax_t)uio->uio_offset < bufsize)
                error = uiomove((char *)buffer + uio->uio_offset,
                    bufsize - uio->uio_offset, uio);
        else
diff -r c311a579d830 -r e6b858ea57f9 sys/miscfs/procfs/procfs_cmdline.c
--- a/sys/miscfs/procfs/procfs_cmdline.c        Fri Sep 27 12:58:54 2019 +0000
+++ b/sys/miscfs/procfs/procfs_cmdline.c        Fri Sep 27 14:36:18 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_cmdline.c,v 1.31 2019/09/26 17:34:08 christos Exp $     */
+/*     $NetBSD: procfs_cmdline.c,v 1.32 2019/09/27 14:36:18 christos Exp $     */
 
 /*
  * Copyright (c) 1999 Jaromir Dolecek <dolecek%ics.muni.cz@localhost>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_cmdline.c,v 1.31 2019/09/26 17:34:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_cmdline.c,v 1.32 2019/09/27 14:36:18 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -52,7 +52,7 @@
        char *buf = __UNCONST(src);
 
        buf += uio->uio_offset - off;
-       if (off + len <= (size_t)uio->uio_offset)
+       if (off + len <= (uintmax_t)uio->uio_offset)
                return 0;
        return uiomove(buf, off + len - uio->uio_offset, cookie);
 }
@@ -90,13 +90,13 @@
                                return error;
                }
                len = strlen(p->p_comm);
-               if (len >= (size_t)uio->uio_offset) {
+               if (len >= (uintmax_t)uio->uio_offset) {
                        start = uio->uio_offset - 1;
                        error = uiomove(p->p_comm + start, len - start, uio);
                        if (error)
                                return error;
                }
-               if (len + 2 >= (size_t)uio->uio_offset) {
+               if (len + 2 >= (uintmax_t)uio->uio_offset) {
                        start = uio->uio_offset - 1 - len;
                        error = uiomove(msg + 1 + start, 2 - start, uio);
                }
diff -r c311a579d830 -r e6b858ea57f9 sys/miscfs/procfs/procfs_limit.c
--- a/sys/miscfs/procfs/procfs_limit.c  Fri Sep 27 12:58:54 2019 +0000
+++ b/sys/miscfs/procfs/procfs_limit.c  Fri Sep 27 14:36:18 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_limit.c,v 1.2 2019/09/26 17:34:08 christos Exp $        */
+/*     $NetBSD: procfs_limit.c,v 1.3 2019/09/27 14:36:18 christos Exp $        */
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_limit.c,v 1.2 2019/09/26 17:34:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_limit.c,v 1.3 2019/09/27 14:36:18 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -81,7 +81,7 @@
                pos += prl(buffer + pos, bufsize - pos, rl[i].rlim_max, '\n');
        }
 
-       if ((size_t)uio->uio_offset < pos)
+       if ((uintmax_t)uio->uio_offset < pos)
                error = uiomove(buffer + uio->uio_offset,
                    pos - uio->uio_offset, uio);
        else
diff -r c311a579d830 -r e6b858ea57f9 sys/miscfs/procfs/procfs_map.c
--- a/sys/miscfs/procfs/procfs_map.c    Fri Sep 27 12:58:54 2019 +0000
+++ b/sys/miscfs/procfs/procfs_map.c    Fri Sep 27 14:36:18 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_map.c,v 1.46 2019/09/26 17:34:08 christos Exp $ */
+/*     $NetBSD: procfs_map.c,v 1.47 2019/09/27 14:36:19 christos Exp $ */
 
 /*
  * Copyright (c) 1993
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_map.c,v 1.46 2019/09/26 17:34:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_map.c,v 1.47 2019/09/27 14:36:19 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -216,7 +216,7 @@
         * The map could have changed between the two reads, and
         * that could result in junk, but typically it does not.
         */
-       if ((size_t)uio->uio_offset < pos)
+       if ((uintmax_t)uio->uio_offset < pos)
                error = uiomove(buffer + uio->uio_offset,
                    pos - uio->uio_offset, uio);
        else



Home | Main Index | Thread Index | Old Index