diff options
author | 2020-06-26 07:28:46 +0000 | |
---|---|---|
committer | 2020-06-26 07:28:46 +0000 | |
commit | c0c93af82c3cd03bb5d4a2c82b9679eb6f329afe (patch) | |
tree | edb6744a47e6dde0aaf8fb1fbc2aa2d5de2cb748 /usr.bin/diff3/diff3prog.c | |
parent | drm/i915/tgl: Make Wa_14010229206 permanent (diff) | |
download | wireguard-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/diff3/diff3prog.c')
-rw-r--r-- | usr.bin/diff3/diff3prog.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/usr.bin/diff3/diff3prog.c b/usr.bin/diff3/diff3prog.c index 992037b6d85..a56bfc7ce7a 100644 --- a/usr.bin/diff3/diff3prog.c +++ b/usr.bin/diff3/diff3prog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff3prog.c,v 1.19 2016/10/18 21:06:52 millert Exp $ */ +/* $OpenBSD: diff3prog.c,v 1.20 2020/06/26 07:28:47 stsp Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -555,9 +555,16 @@ edscript(int n) printf("%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]) != j) + r = fread(block, 1, j, fp[2]); + if (r == 0) { + if (feof(fp[2])) + break; trouble(); + } + if (r != j) + j = r; (void)fwrite(block, 1, j, stdout); } if (!oflag || !overlap[n]) |