Module Name:    src
Committed By:   leot
Date:           Tue Feb 21 09:23:31 UTC 2017

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

Log Message:
Properly check mmap(2) return value. We can end up with a segmentation
fault if the user does not provide a regular file as look(1) file
argument.

Kindly reviewed by <Riastradh>


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 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.16 src/usr.bin/look/look.c:1.17
--- src/usr.bin/look/look.c:1.16	Thu Feb 23 22:57:53 2012
+++ src/usr.bin/look/look.c	Tue Feb 21 09:23:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: look.c,v 1.16 2012/02/23 22:57:53 joerg Exp $	*/
+/*	$NetBSD: look.c,v 1.17 2017/02/21 09:23:31 leot Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)look.c	8.2 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: look.c,v 1.16 2012/02/23 22:57:53 joerg Exp $");
+__RCSID("$NetBSD: look.c,v 1.17 2017/02/21 09:23:31 leot Exp $");
 #endif /* not lint */
 
 /*
@@ -147,7 +147,7 @@ main(int argc, char *argv[])
 		err(2, "%s", file);
 	}
 	if ((front = mmap(NULL, len,
-	    PROT_READ, MAP_FILE|MAP_SHARED, fd, (off_t)0)) == NULL)
+	    PROT_READ, MAP_FILE|MAP_SHARED, fd, (off_t)0)) == MAP_FAILED)
 		err(2, "%s", file);
 	back = front + len;
 	exit(look(string, front, back));

Reply via email to