Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/patch Do not try to mmap a zero length file.



details:   https://anonhg.NetBSD.org/src/rev/fa081493655a
branches:  trunk
changeset: 748349:fa081493655a
user:      joerg <joerg%NetBSD.org@localhost>
date:      Wed Oct 21 17:16:11 2009 +0000

description:
Do not try to mmap a zero length file.

diffstat:

 usr.bin/patch/inp.c |  18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diffs (43 lines):

diff -r 7a99dd0175cd -r fa081493655a usr.bin/patch/inp.c
--- a/usr.bin/patch/inp.c       Wed Oct 21 16:16:24 2009 +0000
+++ b/usr.bin/patch/inp.c       Wed Oct 21 17:16:11 2009 +0000
@@ -1,7 +1,7 @@
 /*
  * $OpenBSD: inp.c,v 1.34 2006/03/11 19:41:30 otto Exp $
  * $DragonFly: src/usr.bin/patch/inp.c,v 1.6 2007/09/29 23:11:10 swildner Exp $
- * $NetBSD: inp.c,v 1.22 2009/06/05 19:55:43 joerg Exp $
+ * $NetBSD: inp.c,v 1.23 2009/10/21 17:16:11 joerg Exp $
  */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: inp.c,v 1.22 2009/06/05 19:55:43 joerg Exp $");
+__RCSID("$NetBSD: inp.c,v 1.23 2009/10/21 17:16:11 joerg Exp $");
 
 #include <sys/types.h>
 #include <sys/file.h>
@@ -261,12 +261,16 @@
        if ((ifd = open(filename, O_RDONLY)) < 0)
                pfatal("can't open file %s", filename);
 
-       i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
-       if (i_womp == MAP_FAILED) {
-               perror("mmap failed");
+       if (i_size) {
+               i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
+               if (i_womp == MAP_FAILED) {
+                       perror("mmap failed");
+                       i_womp = NULL;
+                       close(ifd);
+                       return false;
+               }
+       } else {
                i_womp = NULL;
-               close(ifd);
-               return false;
        }
 
        close(ifd);



Home | Main Index | Thread Index | Old Index