From 433296f8802ccf82eb32da3bfa002df2a8b5095a Mon Sep 17 00:00:00 2001 From: Andy Chu Date: Sat, 19 Mar 2016 23:11:30 -0700 Subject: Fix a buffer overflow in diff -r. We were doing two 32-byte memset()s instead of two 16-byte memset()s. 'dir' referred to the instance (array of 2) and not the struct type. Add some test coverage for diff, including a case that hit this bug. The bug was found by running cp.test under AddressSanitizer, since it happens to use diff. --- tests/diff.test | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 tests/diff.test (limited to 'tests/diff.test') diff --git a/tests/diff.test b/tests/diff.test new file mode 100755 index 00000000..ca0b682b --- /dev/null +++ b/tests/diff.test @@ -0,0 +1,30 @@ +#!/bin/bash + +#testing "name" "command" "result" "infile" "stdin" + +seq 10 > left +seq 11 > right + +expected='--- left ++++ right +@@ -8,3 +8,4 @@ + 8 + 9 + 10 ++11 +' +# Hm this only gives unified diffs? +testing "simple" "diff left right" "$expected" "" "" + + +expected='--- tree1/file ++++ tree2/file +@@ -1 +1 @@ +-foo ++food +' +mkdir -p tree1 tree2 +echo foo > tree1/file +echo food > tree2/file + +testing "simple" "diff -r tree1 tree2 |tee out" "$expected" "" "" -- cgit v1.2.3