Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/ibcs2 Previous fix was incomplete; did not handle...



details:   https://anonhg.NetBSD.org/src/rev/4893e14ca5d1
branches:  trunk
changeset: 555503:4893e14ca5d1
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 19 15:46:16 2003 +0000

description:
Previous fix was incomplete; did not handle negative values.
It is best to use size_t's when dealing with sizes, so that
testing for negative ones, is not needed.

diffstat:

 sys/compat/ibcs2/ibcs2_exec_coff.c |   6 +++---
 sys/compat/ibcs2/ibcs2_exec_xout.c |  16 +++++++++-------
 sys/compat/ibcs2/ibcs2_misc.c      |  14 ++++++++------
 3 files changed, 20 insertions(+), 16 deletions(-)

diffs (135 lines):

diff -r f81b927dd41d -r 4893e14ca5d1 sys/compat/ibcs2/ibcs2_exec_coff.c
--- a/sys/compat/ibcs2/ibcs2_exec_coff.c        Wed Nov 19 15:20:32 2003 +0000
+++ b/sys/compat/ibcs2/ibcs2_exec_coff.c        Wed Nov 19 15:46:16 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ibcs2_exec_coff.c,v 1.10 2003/11/18 19:46:37 itojun Exp $      */
+/*     $NetBSD: ibcs2_exec_coff.c,v 1.11 2003/11/19 15:46:16 christos Exp $    */
 
 /*
  * Copyright (c) 1994, 1995, 1998 Scott Bartram
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_coff.c,v 1.10 2003/11/18 19:46:37 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_coff.c,v 1.11 2003/11/19 15:46:16 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -446,7 +446,7 @@
                size_t resid;
                struct coff_slhdr *slhdr;
                char *buf, *bufp;
-               long len = sh.s_size, path_index, entry_len;
+               size_t len = sh.s_size, path_index, entry_len;
 
                if (len > 64 * 1024)
                        return ENOEXEC;
diff -r f81b927dd41d -r 4893e14ca5d1 sys/compat/ibcs2/ibcs2_exec_xout.c
--- a/sys/compat/ibcs2/ibcs2_exec_xout.c        Wed Nov 19 15:20:32 2003 +0000
+++ b/sys/compat/ibcs2/ibcs2_exec_xout.c        Wed Nov 19 15:46:16 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ibcs2_exec_xout.c,v 1.7 2003/11/05 04:03:21 christos Exp $     */
+/*     $NetBSD: ibcs2_exec_xout.c,v 1.8 2003/11/19 15:46:16 christos Exp $     */
 
 /*
  * Copyright (c) 1994, 1995, 1998 Scott Bartram
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_xout.c,v 1.7 2003/11/05 04:03:21 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_xout.c,v 1.8 2003/11/19 15:46:16 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -110,18 +110,20 @@
        struct xexec *xp;
        struct xext *xep;
 {
-       int error, nseg, i;
+       int error;
+       size_t nseg, i;
        long baddr, bsize;
        struct xseg *xs;
        size_t resid;
+       size_t segsize = (size_t)xep->xe_segsize;
 
-       if (xep->xe_segsize > 16 * sizeof(*xs))
+       if (segsize > 16 * sizeof(*xs))
                return ENOEXEC;
 
        /* read in segment table */
-       xs = (struct xseg *)malloc(xep->xe_segsize, M_TEMP, M_WAITOK);
+       xs = (struct xseg *)malloc(segsize, M_TEMP, M_WAITOK);
        error = vn_rdwr(UIO_READ, epp->ep_vp, (caddr_t)xs,
-                       xep->xe_segsize, xep->xe_segpos,
+                       segsize, xep->xe_segpos,
                        UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred,
                        &resid, p);
        if (error) {
@@ -130,7 +132,7 @@
                return ENOEXEC;
        }
 
-       for (nseg = xep->xe_segsize / sizeof(*xs), i = 0; i < nseg; i++) {
+       for (nseg = segsize / sizeof(*xs), i = 0; i < nseg; i++) {
                switch (xs[i].xs_type) {
                case XS_TTEXT:  /* text segment */
 
diff -r f81b927dd41d -r 4893e14ca5d1 sys/compat/ibcs2/ibcs2_misc.c
--- a/sys/compat/ibcs2/ibcs2_misc.c     Wed Nov 19 15:20:32 2003 +0000
+++ b/sys/compat/ibcs2/ibcs2_misc.c     Wed Nov 19 15:46:16 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ibcs2_misc.c,v 1.67 2003/08/07 16:30:44 agc Exp $      */
+/*     $NetBSD: ibcs2_misc.c,v 1.68 2003/11/19 15:46:16 christos Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -95,7 +95,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ibcs2_misc.c,v 1.67 2003/08/07 16:30:44 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibcs2_misc.c,v 1.68 2003/11/19 15:46:16 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -418,7 +418,8 @@
        struct iovec aiov;
        struct ibcs2_dirent idb;
        off_t off;                      /* true file offset */
-       int buflen, error, eofflag;
+       size_t buflen;
+       int error, eofflag;
        off_t *cookiebuf = NULL, *cookie;
        int ncookies;
 
@@ -434,7 +435,7 @@
                error = EINVAL;
                goto out1;
        }
-       buflen = min(MAXBSIZE, SCARG(uap, nbytes));
+       buflen = min(MAXBSIZE, (size_t)SCARG(uap, nbytes));
        buf = malloc(buflen, M_TEMP, M_WAITOK);
        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
        off = fp->f_offset;
@@ -544,7 +545,8 @@
                ibcs2_ino_t ino;
                char name[14];
        } idb;
-       int buflen, error, eofflag;
+       size_t buflen;
+       int error, eofflag;
        size_t size;
        off_t *cookiebuf = NULL, *cookie;
        off_t off;                      /* true file offset */
@@ -566,7 +568,7 @@
                FILE_UNUSE(fp, p);
                return sys_read(l, uap, retval);
        }
-       buflen = min(MAXBSIZE, max(DEV_BSIZE, SCARG(uap, nbytes)));
+       buflen = min(MAXBSIZE, max(DEV_BSIZE, (size_t)SCARG(uap, nbytes)));
        buf = malloc(buflen, M_TEMP, M_WAITOK);
        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
        off = fp->f_offset;



Home | Main Index | Thread Index | Old Index