Source-Changes-HG archive

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

[src/trunk]: src/sys/msdosfs msdosfs_read(): avoid integer overflow for files...



details:   https://anonhg.NetBSD.org/src/rev/303de025ddae
branches:  trunk
changeset: 485246:303de025ddae
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat Apr 22 22:45:37 2000 +0000

description:
msdosfs_read(): avoid integer overflow for files > 2GB,  when
        difference between current read position and file size
        is bigger than 2GB

This fixes problem first noted in FreeBSD PR#15639 and sent
by Martin J. Laubach in kern/9046, though the implementation
differs a bit.

diffstat:

 sys/msdosfs/msdosfs_vnops.c |  11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diffs (34 lines):

diff -r bf4e7635d828 -r 303de025ddae sys/msdosfs/msdosfs_vnops.c
--- a/sys/msdosfs/msdosfs_vnops.c       Sat Apr 22 22:36:14 2000 +0000
+++ b/sys/msdosfs/msdosfs_vnops.c       Sat Apr 22 22:45:37 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_vnops.c,v 1.95 2000/03/30 12:23:20 augustss Exp $      */
+/*     $NetBSD: msdosfs_vnops.c,v 1.96 2000/04/22 22:45:37 jdolecek Exp $      */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -466,7 +466,7 @@
                struct ucred *a_cred;
        } */ *ap = v;
        int error = 0;
-       int diff;
+       int64_t diff;
        int blsize;
        int isadir;
        long n;
@@ -492,11 +492,12 @@
                lbn = de_cluster(pmp, uio->uio_offset);
                on = uio->uio_offset & pmp->pm_crbomask;
                n = min((u_long) (pmp->pm_bpcluster - on), uio->uio_resid);
-               diff = dep->de_FileSize - uio->uio_offset;
-               if (diff <= 0)
+               if (uio->uio_offset >= dep->de_FileSize)
                        return (0);
+               /* file size (and hence diff) may be up to 4GB */
+               diff = dep->de_FileSize - uio->uio_offset;
                if (diff < n)
-                       n = diff;
+                       n = (long) diff;
                /* convert cluster # to block # if a directory */
                if (isadir) {
                        error = pcbmap(dep, lbn, &lbn, 0, &blsize);



Home | Main Index | Thread Index | Old Index