]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: shuf: ensure memory exhaustion is handled gracefully
authoroech3 <79379754+oech3@users.noreply.github.com>
Mon, 2 Mar 2026 11:56:23 +0000 (11:56 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 2 Mar 2026 11:59:25 +0000 (11:59 +0000)
* tests/shuf/shuf.sh: Ensure we exit 1 upon failure
to allocate memory.
https://github.com/uutils/coreutils/issues/11170
https://github.com/coreutils/coreutils/pull/209

tests/shuf/shuf.sh

index 9258ceec6ab547580f839afaa373c73fcd87b8ad..346d9c95660a5a43b13fc6f6b2531a72a0e2f131 100755 (executable)
@@ -77,6 +77,11 @@ shuf --zero-terminated -i 1-1 > out || fail=1
 printf '1\0' > exp || framework_failure_
 cmp out exp || { fail=1; echo "missing NUL terminator?" 1>&2; }
 
+# Ensure shuf exits with 1 if memory exhausted
+vm=$(get_min_ulimit_v_ shuf -i1-1) && (ulimit -v $vm shuf -i1-1) && {
+  (ulimit -v $vm && returns_ 1 shuf -i1-$SIZE_MAX) || fail=1
+}
+
 # Ensure shuf -n operates efficiently for small n. Before coreutils-8.13
 # this would try to allocate $SIZE_MAX * sizeof(size_t)
 timeout 10 shuf -i1-$SIZE_MAX -n2 >/dev/null ||