diff src/lib/mmap-util.c @ 43:526284657da7 HEAD

Fail if we try to mmap() files larger than 2G fully to memory
author Timo Sirainen <tss@iki.fi>
date Tue, 27 Aug 2002 05:27:05 +0300
parents 622e22c0486f
children 4a7ab9e94f25
line wrap: on
line diff
--- a/src/lib/mmap-util.c	Tue Aug 27 05:25:33 2002 +0300
+++ b/src/lib/mmap-util.c	Tue Aug 27 05:27:05 2002 +0300
@@ -28,10 +28,19 @@
 
 static void *mmap_file(int fd, size_t *length, int access)
 {
-	*length = lseek(fd, 0, SEEK_END);
-	if ((off_t)*length == -1)
+	off_t size;
+
+	size = lseek(fd, 0, SEEK_END);
+	if (size == -1)
 		return MAP_FAILED;
 
+	if (size > INT_MAX) {
+		/* too large file to map into memory */
+		errno = EFBIG;
+		return MAP_FAILED;
+	}
+
+	*length = (size_t)size;
 	if (*length == 0)
 		return NULL;