diff --git a/NEWS b/NEWS index 9a8d2e1..73ff83b 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ GNU diffutils NEWS -*- outline -*- ** Bug fixes + diff3 no longer malfunctions due to use-after-free + [bug introduced in 3.4] + diff --color no longer colorizes when TERM=dumb diff --git a/src/diff3.c b/src/diff3.c index 6ef90f4..0eb643e 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -1039,7 +1039,6 @@ process_diff (char const *filea, *block_list_end = NULL; *last_block = bptr; - free (diff_contents); return block_list; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 77d9fc3..66e25a5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,6 +6,7 @@ TESTS = \ binary \ brief-vs-stat-zero-kernel-lies \ colliding-file-names \ + diff3 \ excess-slash \ help-version \ function-line-vs-leading-space \ diff --git a/tests/diff3 b/tests/diff3 new file mode 100644 index 0000000..a1fc287 --- /dev/null +++ b/tests/diff3 @@ -0,0 +1,30 @@ +#!/bin/sh +# This would malfunction in diff-3.4 + +. "${srcdir=.}/init.sh"; path_prepend_ ../src + +echo a > a || framework_failure_ +echo b > b || framework_failure_ +echo c > c || framework_failure_ +cat <<'EOF' > exp || framework_failure_ +==== +1:1c + a +2:1c + b +3:1c + c +EOF + +fail=0 + +diff3 a b c > out 2> err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Repeat, but with all three files the same: +diff3 a a a > out 2> err || fail=1 +compare /dev/null out || fail=1 +compare /dev/null err || fail=1 + +Exit $fail