From e1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 18:58:41 +0200 Subject: Adding upstream version 9.4. Signed-off-by: Daniel Baumann --- tests/truncate/truncate-dangling-symlink.sh | 28 +++++++++++++++ tests/truncate/truncate-dir-fail.sh | 25 +++++++++++++ tests/truncate/truncate-fail-diag.sh | 43 ++++++++++++++++++++++ tests/truncate/truncate-fifo.sh | 27 ++++++++++++++ tests/truncate/truncate-no-create-missing.sh | 26 ++++++++++++++ tests/truncate/truncate-overflow.sh | 39 ++++++++++++++++++++ tests/truncate/truncate-owned-by-other.sh | 35 ++++++++++++++++++ tests/truncate/truncate-parameters.sh | 54 ++++++++++++++++++++++++++++ tests/truncate/truncate-relative.sh | 35 ++++++++++++++++++ 9 files changed, 312 insertions(+) create mode 100755 tests/truncate/truncate-dangling-symlink.sh create mode 100755 tests/truncate/truncate-dir-fail.sh create mode 100755 tests/truncate/truncate-fail-diag.sh create mode 100755 tests/truncate/truncate-fifo.sh create mode 100755 tests/truncate/truncate-no-create-missing.sh create mode 100755 tests/truncate/truncate-overflow.sh create mode 100755 tests/truncate/truncate-owned-by-other.sh create mode 100755 tests/truncate/truncate-parameters.sh create mode 100755 tests/truncate/truncate-relative.sh (limited to 'tests/truncate') diff --git a/tests/truncate/truncate-dangling-symlink.sh b/tests/truncate/truncate-dangling-symlink.sh new file mode 100755 index 0000000..d2e3b79 --- /dev/null +++ b/tests/truncate/truncate-dangling-symlink.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Make sure truncate can create a file through a dangling symlink. + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + +ln -s truncate-target t-symlink + +truncate -s0 t-symlink || fail=1 + +test -f truncate-target || fail=1 + +Exit $fail diff --git a/tests/truncate/truncate-dir-fail.sh b/tests/truncate/truncate-dir-fail.sh new file mode 100755 index 0000000..cee7801 --- /dev/null +++ b/tests/truncate/truncate-dir-fail.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Make sure truncate fails for a directory. + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + +# truncate on dir not allowed +returns_ 1 truncate -s+0 . || fail=1 + +Exit $fail diff --git a/tests/truncate/truncate-fail-diag.sh b/tests/truncate/truncate-fail-diag.sh new file mode 100755 index 0000000..2257548 --- /dev/null +++ b/tests/truncate/truncate-fail-diag.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# make sure truncate gives reasonable diagnostics +# Note open() checks for trailing '/' before checking for existence +# open (".", O_CREAT & (O_WRONLY | O_RDWR), ...) -> EISDIR +# open ("missing/", O_CREAT & (O_WRONLY | O_RDWR), ...) -> EISDIR +# open ("missing/file", O_CREAT & (O_WRONLY | O_RDWR), ...) -> ENOENT + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate +skip_if_root_ + + +d1=no + +dir=$d1/such-dir +truncate -s0 $dir > out 2>&1 && fail=1 +cat < exp +truncate: cannot open '$dir' for writing: No such file or directory +EOF +compare exp out || fail=1 + +dir=$d1/ +truncate -s0 $dir > out 2>&1 && fail=1 +#The following can be returned at least +#truncate: cannot open '$dir' for writing: Not a directory +#truncate: cannot open '$dir' for writing: Is a directory + +Exit $fail diff --git a/tests/truncate/truncate-fifo.sh b/tests/truncate/truncate-fifo.sh new file mode 100755 index 0000000..c89555c --- /dev/null +++ b/tests/truncate/truncate-fifo.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Make sure truncate works on fifos without hanging + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + +mkfifo_or_skip_ fifo + +timeout 10 truncate -s0 fifo +test "$?" = 124 && fail=1 + +Exit $fail diff --git a/tests/truncate/truncate-no-create-missing.sh b/tests/truncate/truncate-no-create-missing.sh new file mode 100755 index 0000000..bf6e657 --- /dev/null +++ b/tests/truncate/truncate-no-create-missing.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Ensure that truncate -c no-such-file doesn't fail. + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + + +# truncate -c no-such-file should not fail. +truncate -s0 -c no-such-file || fail=1 + +Exit $fail diff --git a/tests/truncate/truncate-overflow.sh b/tests/truncate/truncate-overflow.sh new file mode 100755 index 0000000..22bda70 --- /dev/null +++ b/tests/truncate/truncate-overflow.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Validate truncate integer overflow + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate +getlimits_ + + +# -= overflow +truncate -s-1 create-zero-len-file || fail=1 + +echo > non-empty-file + +# signed overflow +returns_ 1 truncate -s$OFF_T_OFLOW file || fail=1 + +# += signed overflow +returns_ 1 truncate -s+$OFF_T_MAX non-empty-file || fail=1 + +# *= signed overflow +IO_BLOCK_OFLOW=$(expr $OFF_T_MAX / $(stat -f -c%s .) + 1) +returns_ 1 truncate --io-blocks --size=$IO_BLOCK_OFLOW file || fail=1 + +Exit $fail diff --git a/tests/truncate/truncate-owned-by-other.sh b/tests/truncate/truncate-owned-by-other.sh new file mode 100755 index 0000000..f213e8f --- /dev/null +++ b/tests/truncate/truncate-owned-by-other.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Demonstrate that "truncate -s0 writable-but-owned-by-other" works. + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + +require_root_ + +# Create a file owned by root, and writable by $NON_ROOT_USERNAME. +echo > root-owned || framework_failure_ +chgrp +$NON_ROOT_GID . root-owned || framework_failure_ +chmod g+w root-owned + +# Ensure that the current directory is searchable by $NON_ROOT_USERNAME. +chmod g+x . + +chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ + truncate -s0 root-owned || fail=1 + +Exit $fail diff --git a/tests/truncate/truncate-parameters.sh b/tests/truncate/truncate-parameters.sh new file mode 100755 index 0000000..a7f5685 --- /dev/null +++ b/tests/truncate/truncate-parameters.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Validate truncate parameter combinations + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + + +# must specify at least 1 file +returns_ 1 truncate --size=0 || fail=1 + +# must specify size. don't default to 0 +returns_ 1 truncate file || fail=1 + +# mixture of absolute size & reference not allowed +returns_ 1 truncate --size=0 --reference=file file || fail=1 + +# blocks without size is not valid +returns_ 1 truncate --io-blocks --reference=file file || fail=1 + +# must specify valid numbers +returns_ 1 truncate --size="invalid" file || fail=1 + +# spaces not significant around size +returns_ 1 truncate --size="> -1" file || fail=1 +truncate --size=" >1" file || fail=1 #file now 1 +truncate --size=" +1" file || fail=1 #file now 2 +test $(stat --format %s file) = 2 || fail=1 + +# reference allowed with relative size +truncate --size=" +1" -r file file || fail=1 #file now 3 +test $(stat --format %s file) = 3 || fail=1 + +# reference allowed alone also +truncate -r file file || fail=1 #file still 3 +test $(stat --format %s file) = 3 || fail=1 +truncate -r file file2 || fail=1 #file2 now 3 +test $(stat --format %s file2) = 3 || fail=1 + +Exit $fail diff --git a/tests/truncate/truncate-relative.sh b/tests/truncate/truncate-relative.sh new file mode 100755 index 0000000..57be8b4 --- /dev/null +++ b/tests/truncate/truncate-relative.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Validate truncate relative sizes + +# Copyright (C) 2008-2023 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ truncate + + +# mixture of relative modifiers not allowed +returns_ 1 truncate --size="+>0" file || fail=1 + +# mixture of relative modifiers not allowed +returns_ 1 truncate --size=">+0" file || fail=1 + +# division by zero +returns_ 1 truncate --size="/0" file || fail=1 + +# division by zero +returns_ 1 truncate --size="%0" file || fail=1 + +Exit $fail -- cgit v1.2.3