delete MAP_FILE, check file size before mmap'ing, print file name on
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 25 Jun 1992 00:41:23 +0000 (16:41 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 25 Jun 1992 00:41:23 +0000 (16:41 -0800)
error

SCCS-vsn: usr.bin/tail/forward.c 5.8
SCCS-vsn: usr.bin/tail/reverse.c 5.7
SCCS-vsn: usr.bin/tail/tail.c 5.12

usr/src/usr.bin/tail/forward.c
usr/src/usr.bin/tail/reverse.c
usr/src/usr.bin/tail/tail.c

index 0dabbe1..b198435 100644 (file)
@@ -9,13 +9,15 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)forward.c  5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)forward.c  5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/mman.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/mman.h>
+
+#include <limits.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
@@ -174,9 +176,14 @@ rlines(fp, off, sbp)
        if (!(size = sbp->st_size))
                return;
 
        if (!(size = sbp->st_size))
                return;
 
+       if (size > SIZE_T_MAX) {
+               err(0, "%s: %s", fname, strerror(EFBIG));
+               return;
+       }
+
        if ((start = mmap(NULL, (size_t)size,
        if ((start = mmap(NULL, (size_t)size,
-           PROT_READ, MAP_FILE, fileno(fp), (off_t)0)) == (caddr_t)-1) {
-               err(0, "%s", strerror(errno));
+           PROT_READ, 0, fileno(fp), (off_t)0)) == (caddr_t)-1) {
+               err(0, "%s: %s", fname, strerror(EFBIG));
                return;
        }
 
                return;
        }
 
@@ -194,8 +201,8 @@ rlines(fp, off, sbp)
                ierr();
                return;
        }
                ierr();
                return;
        }
-       if (munmap(start, size)) {
-               err(0, "%s", strerror(errno));
+       if (munmap(start, (size_t)size)) {
+               err(0, "%s: %s", fname, strerror(errno));
                return;
        }
 }
                return;
        }
 }
index d1a3bcb..4c8c3b8 100644 (file)
@@ -9,12 +9,14 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)reverse.c  5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)reverse.c  5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
+
+#include <limits.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -88,9 +90,14 @@ r_reg(fp, style, off, sbp)
        if (!(size = sbp->st_size))
                return;
 
        if (!(size = sbp->st_size))
                return;
 
+       if (size > SIZE_T_MAX) {
+               err(0, "%s: %s", fname, strerror(EFBIG));
+               return;
+       }
+
        if ((p = mmap(NULL, (size_t)size,
        if ((p = mmap(NULL, (size_t)size,
-           PROT_READ, MAP_FILE, fileno(fp), (off_t)0)) == (caddr_t)-1) {
-               err(0, "%s", strerror(errno));
+           PROT_READ, 0, fileno(fp), (off_t)0)) == (caddr_t)-1) {
+               err(0, "%s: %s", fname, strerror(EFBIG));
                return;
        }
        p += size - 1;
                return;
        }
        p += size - 1;
index 17fe8f3..2315cc4 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)tail.c     5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)tail.c     5.12 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>