* src/getlimits.c (UID_T_MIN, GID_T_MIN): Define to the actual minimum
instead of zero, so it can be used to check for signedness.
* src/install.c (get_ids): Reject (uid_t) -1 for the owner ID
and (gid_t) -1 for the group ID.
* tests/install/basic-1.sh: Invoke getlimits_. Add two test cases.
* NEWS: Mention the bug fix.
---
NEWS | 5 +++++
src/getlimits.c | 10 ++++++++--
src/install.c | 6 ++++--
tests/install/basic-1.sh | 21 +++++++++++++++++++++
4 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/NEWS b/NEWS
index ec0b29111..5965da518 100644
--- a/NEWS
+++ b/NEWS
@@ -186,6 +186,11 @@ GNU coreutils NEWS -*-
outline -*-
referenced.
[This bug was present in "the beginning".]
+ 'install' now exits with an error when given the maximum value represented by
+ uid_t and gid_t to the --owner and --group options, respectively.
Previously,
+ it would accept them but leave the ownership of created files unchanged.
+ [This bug was present in "the beginning".]
+
'ln' now avoids races that could lose backup data in unlikely circumstances,
on systems providing support for atomic rename.
[This bug was present in "the beginning".]
diff --git a/src/getlimits.c b/src/getlimits.c
index b291c8b81..b428475f9 100644
--- a/src/getlimits.c
+++ b/src/getlimits.c
@@ -56,6 +56,14 @@
# define OFF64_T_MIN TYPE_MINIMUM (off64_t)
#endif
+#ifndef UID_T_MIN
+# define UID_T_MIN TYPE_MINIMUM (uid_t)
+#endif
+
+#ifndef GID_T_MIN
+# define GID_T_MIN TYPE_MINIMUM (gid_t)
+#endif
+
#ifndef SIGRTMIN
# define SIGRTMIN 0
# undef SIGRTMAX
@@ -73,8 +81,6 @@
#define UINT_MIN 0
#define ULONG_MIN 0
#define UINTMAX_MIN 0
-#define UID_T_MIN 0
-#define GID_T_MIN 0
void
usage (int status)
diff --git a/src/install.c b/src/install.c
index 0f58e91e6..0c225a876 100644
--- a/src/install.c
+++ b/src/install.c
@@ -577,7 +577,8 @@ get_ids (void)
{
uintmax_t tmp;
if (xstrtoumax (owner_name, NULL, 0, &tmp, "") != LONGINT_OK
- || ckd_add (&owner_id, tmp, 0))
+ || ckd_add (&owner_id, tmp, 0)
+ || owner_id == (uid_t) -1)
error (EXIT_FAILURE, 0, _("invalid user %s"),
quoteaf (owner_name));
}
@@ -595,7 +596,8 @@ get_ids (void)
{
uintmax_t tmp;
if (xstrtoumax (group_name, NULL, 0, &tmp, "") != LONGINT_OK
- || ckd_add (&group_id, tmp, 0))
+ || ckd_add (&group_id, tmp, 0)
+ || group_id == (gid_t) -1)
error (EXIT_FAILURE, 0, _("invalid group %s"),
quoteaf (group_name));
}
diff --git a/tests/install/basic-1.sh b/tests/install/basic-1.sh
index dcc8b77de..8fb1742c6 100755
--- a/tests/install/basic-1.sh
+++ b/tests/install/basic-1.sh
@@ -19,6 +19,7 @@
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ ginstall
skip_if_root_
+getlimits_
dir=dir
file=file
@@ -194,4 +195,24 @@ ginstall -d testdir --mode='u+rwx,g+rx,o+r' || fail=1
mode=$(ls -ld testdir|cut -b-10)
test "$mode" = drwxr-xr-- || fail=1
+# coreutils-9.12 and earlier would accept (uid_t) -1 and (gid_t) -1 for the
+# --owner and --group arguments, respectively, while leaving the ownership of
+# created files unchanged, instead of diagnosing them as invalid. Note that
+# this bug occurred on most platforms where these types are unsigned; however
+# POSIX allows them to be signed, so check that first.
+if test -z "$UID_T_MIN"; then
+ echo "ginstall: invalid user '$UID_T_MAX'" >exp-err || framework_failure_
+ returns_ 1 ginstall --owner $UID_T_MAX file1 testdir >out 2>err || fail=1
+ compare /dev/null out || fail=1
+ compare exp-err err || fail=1
+ returns_ 1 test -f testdir/file1 || fail=1
+fi
+if test -z "$GID_T_MIN"; then
+ echo "ginstall: invalid group '$GID_T_MAX'" >exp-err || framework_failure_
+ returns_ 1 ginstall --group $GID_T_MAX file1 testdir >out 2>err || fail=1
+ compare /dev/null out || fail=1
+ compare exp-err err || fail=1
+ returns_ 1 test -f testdir/file1 || fail=1
+fi
+
Exit $fail
--
2.56.1