From: oech3 <79379754+oech3@users.noreply.github.com> Date: Mon, 2 Mar 2026 11:56:23 +0000 (+0000) Subject: tests: shuf: ensure memory exhaustion is handled gracefully X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55c06e3ecb58547fc7d33d328b5188047bda5cfe;p=thirdparty%2Fcoreutils.git tests: shuf: ensure memory exhaustion is handled gracefully * 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 --- diff --git a/tests/shuf/shuf.sh b/tests/shuf/shuf.sh index 9258ceec6a..346d9c9566 100755 --- a/tests/shuf/shuf.sh +++ b/tests/shuf/shuf.sh @@ -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 ||