git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] commit-graph tests: fix cryptic unportable "dd" invocation

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 21, 2019, 19:28 UTC
Message-ID
<20190221192849.6581-3-avarab@gmail.com>
In-Reply-To
<xmqq8sybz7b2.fsf@gitster-ct.c.googlers.com>

Change an unportable invocation of "dd" that truncated the commit-graph to call Perl's truncate() function instead.

In POSIX it is unspecified what happens when count=0 is provided[1]. The NetBSD "dd" behavior differs from GNU (and seemingly other BSDs), which as left this test broken since d2b86fbaa1 ("commit-graph: fix buffer read-overflow", 2019-01-15).

In POSIX the truncate(2) and ftruncate(2) functions are portable. We've used the latter since 271421cd34 ("Update partial HTTP transfers.", 2005-09-30), but the truncate(1) command-line tool is GNU-specific. Thus let's use Perl's version of it. We could also just introduce a "test-tool truncate" in the future if we wanted to avoid shelling out to perl.

On Linux and NetBSD we don't need the "if -s $ARGV[0] > $ARGV[1]" condition I'm adding. We never have a $zero_pos longer than the file being truncated. But let's have that condition to future-proof the code, and because "the behavior is undefined if LENGTH is greater than the length of the file" (perldoc -f truncate).

1. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/dd.html
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5318-commit-graph.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
index d4bd1522fe..d99bea6cce 100755
--- a/t/t5318-commit-graph.sh
+++ b/t/t5318-commit-graph.sh
@@ -382,7 +382,8 @@ corrupt_graph_and_verify() {
 	test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
 	cp $objdir/info/commit-graph commit-graph-backup &&
 	printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
-	dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" count=0 &&
+	perl -we 'truncate $ARGV[0], $ARGV[1] if -s $ARGV[0] > $ARGV[1]' \
+		$objdir/info/commit-graph $zero_pos &&
 	generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
 	test_must_fail git commit-graph verify 2>test_err &&
 	grep -v "^+" test_err >err &&
-- 
2.21.0.rc0.258.g878e2cd30e
Previous: Junio C HamanoNext: SZEDER Gábor
Message 18 of 25 in “[ANNOUNCE] Git v2.21.0-rc2”
  1. Junio C HamanoFeb 19, 2019
  2. Randall S. BeckerFeb 20, 2019
  3. Junio C HamanoFeb 20, 2019
  4. Johannes SchindelinFeb 20, 2019
  5. Duy NguyenFeb 21, 2019
  6. brian m. carlsonFeb 21, 2019
  7. Duy NguyenFeb 22, 2019
  8. Randall S. BeckerFeb 21, 2019
  9. Junio C HamanoFeb 21, 2019
  10. SZEDER GáborFeb 21, 2019
  11. Randall S. BeckerFeb 21, 2019
  12. Randall S. BeckerFeb 21, 2019
  13. Git for Windows v2.21.0-rc2, was Re: [ANNOUNCE] Git v2.21.0-rc2Johannes Schindelin, Feb 21, 2019
  14. 0/2 BSD portability fixes for 2.21.0-rc2Ævar Arnfjörð Bjarmason, Feb 21, 2019
  15. Josh SteadmonFeb 22, 2019
  16. 1/2 tests: fix unportable "\?" and "\+" regex syntaxÆvar Arnfjörð Bjarmason, Feb 21, 2019
  17. Junio C HamanoFeb 22, 2019
  18. 2/2 commit-graph tests: fix cryptic unportable "dd" invocationÆvar Arnfjörð Bjarmason, Feb 21, 2019
  19. SZEDER GáborFeb 21, 2019
  20. Ævar Arnfjörð BjarmasonFeb 21, 2019
  21. SZEDER GáborFeb 22, 2019
  22. Ævar Arnfjörð BjarmasonFeb 22, 2019
  23. Junio C HamanoFeb 22, 2019
  24. Todd ZullingerFeb 22, 2019
  25. commit-graph tests: fix unportable "dd" invocationJunio C Hamano, Feb 22, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.