Module Name:    src
Committed By:   christos
Date:           Sun Apr 26 15:55:50 UTC 2009

Modified Files:
        src/usr.bin/look: look.c

Log Message:
fix broken overflow test.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/look/look.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/look/look.c
diff -u src/usr.bin/look/look.c:1.13 src/usr.bin/look/look.c:1.14
--- src/usr.bin/look/look.c:1.13	Sun Apr 12 10:01:20 2009
+++ src/usr.bin/look/look.c	Sun Apr 26 11:55:50 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: look.c,v 1.13 2009/04/12 14:01:20 lukem Exp $	*/
+/*	$NetBSD: look.c,v 1.14 2009/04/26 15:55:50 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)look.c	8.2 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: look.c,v 1.13 2009/04/12 14:01:20 lukem Exp $");
+__RCSID("$NetBSD: look.c,v 1.14 2009/04/26 15:55:50 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -103,6 +103,7 @@
 	int ch, fd, termchar;
 	char *back, *front, *string, *p;
 	const char *file;
+	size_t len;
 
 	string = NULL;
 	file = _PATH_WORDS;
@@ -143,12 +144,15 @@
 
 	if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb))
 		err(2, "%s", file);
-	if (sb.st_size > (off_t)SIZE_T_MAX)
-		err(2, "%s: %s", file, strerror(EFBIG));
-	if ((front = mmap(NULL, (size_t)sb.st_size,
+	len = (size_t)sb.st_size;
+	if ((off_t)len != sb.st_size) {
+		errno = EFBIG;
+		err(2, "%s", file);
+	}
+	if ((front = mmap(NULL, len,
 	    PROT_READ, MAP_FILE|MAP_SHARED, fd, (off_t)0)) == NULL)
 		err(2, "%s", file);
-	back = front + sb.st_size;
+	back = front + len;
 	exit(look(string, front, back));
 }
 

Reply via email to