summaryrefslogtreecommitdiffstats
path: root/usr.bin/patch/inp.c
diff options
context:
space:
mode:
authorajacoutot <ajacoutot@openbsd.org>2012-04-10 14:46:34 +0000
committerajacoutot <ajacoutot@openbsd.org>2012-04-10 14:46:34 +0000
commit9232b9afea0f58b95500946754d5b7bb06b57436 (patch)
tree08814a221e7d90ef1d91c9bc8e7a11664bada12d /usr.bin/patch/inp.c
parentWhen converting the timeout to ticks, both round up and add one to account (diff)
downloadwireguard-openbsd-9232b9afea0f58b95500946754d5b7bb06b57436.tar.xz
wireguard-openbsd-9232b9afea0f58b95500946754d5b7bb06b57436.zip
Don't try to mmap a zero length file, from NetBSD.
Needed after the recent mmap(2) change. ok ariane@
Diffstat (limited to 'usr.bin/patch/inp.c')
-rw-r--r--usr.bin/patch/inp.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index 6657d198390..eed1aefad68 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inp.c,v 1.35 2009/10/27 23:59:41 deraadt Exp $ */
+/* $OpenBSD: inp.c,v 1.36 2012/04/10 14:46:34 ajacoutot Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -243,12 +243,16 @@ plan_a(const char *filename)
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);