]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: dd: ensure memory exhaustion is handled gracefully
authoroech3 <79379754+oech3@users.noreply.github.com>
Wed, 1 Apr 2026 11:37:09 +0000 (20:37 +0900)
committerPádraig Brady <P@draigBrady.com>
Wed, 1 Apr 2026 15:54:12 +0000 (16:54 +0100)
* tests/dd/no-allocate.sh: Ensure we exit 1 upon mem allocation failure.
Also check other buffer size edge cases.
https://github.com/uutils/coreutils/issues/11436
https://github.com/uutils/coreutils/issues/11580
https://github.com/coreutils/coreutils/pull/235

tests/dd/no-allocate.sh

index 76726a17092ba8f92fc8f1698e0bbecd4e79e1f0..f5ed903fcc3551bd58182abaf1c9e4789fb9e27c 100755 (executable)
@@ -25,6 +25,16 @@ vm=$(get_min_ulimit_v_ timeout 10 dd if=f of=f2 status=none) \
   || skip_ 'shell lacks ulimit, or ASAN enabled'
 rm f f2 || framework_failure_
 
+# Ensure dd exits with 1 if memory exhausted
+(ulimit -v $vm && returns_ 1 \
+ dd if=/dev/null of=/dev/null bs=$(($SSIZE_MAX-1))) || fail=1
+# Ensure dd exits with 1 on numeric overflow
+(ulimit -v $vm && returns_ 1 \
+ dd if=/dev/null of=/dev/null bs=$SIZE_OFLOW) || fail=1
+# Ensure dd exits with 1 on invalid number
+(ulimit -v $vm && returns_ 1 \
+ dd if=/dev/null of=/dev/null bs=0) || fail=1
+
 # count and skip are zero, we don't need to allocate memory
 (ulimit -v $vm && dd  bs=30M count=0) || fail=1
 (ulimit -v $vm && dd ibs=30M count=0) || fail=1