summaryrefslogtreecommitdiffstats
path: root/usr.bin/cvs/diff3.c
diff options
context:
space:
mode:
authorstsp <stsp@openbsd.org>2020-06-26 07:28:46 +0000
committerstsp <stsp@openbsd.org>2020-06-26 07:28:46 +0000
commitc0c93af82c3cd03bb5d4a2c82b9679eb6f329afe (patch)
treeedb6744a47e6dde0aaf8fb1fbc2aa2d5de2cb748 /usr.bin/cvs/diff3.c
parentdrm/i915/tgl: Make Wa_14010229206 permanent (diff)
downloadwireguard-openbsd-c0c93af82c3cd03bb5d4a2c82b9679eb6f329afe.tar.xz
wireguard-openbsd-c0c93af82c3cd03bb5d4a2c82b9679eb6f329afe.zip
Fix merging of files that lack newlines for diff(3), OpenRCS, and OpenCVS.
Merges with a file that lacks newlines (\n) were triggering a fatal error. This could be easily reproduced with merge(1) and diff3(1): $ echo foo > foo $ echo bar > bar $ echo -n baz > baz $ merge -p foo bar baz merge: failed to merge $ diff3 -E foo bar baz 1a ======= diff3prog: logic error $ Fix this by properly handling short reads from the third file argument. Only the third file argument triggered the problem. The other input files were already handled correctly. ok millert@
Diffstat (limited to 'usr.bin/cvs/diff3.c')
-rw-r--r--usr.bin/cvs/diff3.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/usr.bin/cvs/diff3.c b/usr.bin/cvs/diff3.c
index e8e0512d85a..f0fee1c1925 100644
--- a/usr.bin/cvs/diff3.c
+++ b/usr.bin/cvs/diff3.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff3.c,v 1.63 2019/06/28 13:35:00 deraadt Exp $ */
+/* $OpenBSD: diff3.c,v 1.64 2020/06/26 07:28:47 stsp Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -798,9 +798,16 @@ edscript(int n)
diff_output("%da\n=======\n", de[n].old.to -1);
(void)fseek(fp[2], (long)de[n].new.from, SEEK_SET);
for (k = de[n].new.to-de[n].new.from; k > 0; k-= j) {
+ size_t r;
j = k > BUFSIZ ? BUFSIZ : k;
- if (fread(block, 1, j, fp[2]) != (size_t)j)
+ r = fread(block, 1, j, fp[2]);
+ if (r == 0) {
+ if (feof(fp[2]))
+ break;
return (-1);
+ }
+ if (r != (size_t)j)
+ j = r;
block[j] = '\0';
diff_output("%s", block);
}