From 57fe9ecd694459c44fa59b903d5dbb001f22ce66 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Sun, 21 Jun 2026 20:45:09 -0700 Subject: [PATCH] tests: dd: check that files are opened with O_TRUNC * tests/dd/misc.sh: Add the test case. --- tests/dd/misc.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/dd/misc.sh b/tests/dd/misc.sh index aa776b137..5e2eb8ed5 100755 --- a/tests/dd/misc.sh +++ b/tests/dd/misc.sh @@ -19,6 +19,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ dd +uses_strace_ export LC_ALL=C tmp_in=dd-in @@ -129,5 +130,16 @@ if test -c /dev/tty && >/dev/tty; then dd if=/dev/null of=/dev/tty || fail=1 fi +# Ensure that the output file is opened with O_TRUNC. +if strace -o /dev/null -e inject=truncate,ftruncate:error=EIO true; then + echo a > $tmp_out || framework_failure_ + strace --quiet=all -o /dev/null \ + -e inject=truncate,ftruncate:error=EIO -P $tmp_out \ + dd if=/dev/null of=$tmp_out status=none skip=1B >out 2>err || fail=1 + compare /dev/null out || fail=1 + compare /dev/null err || fail=1 + compare /dev/null $tmp_out || fail=1 +fi + Exit $fail