forked from pool/coreutils
c76409f6df
Copy from Base:System/coreutils based on submit request 39394 from user psmt OBS-URL: https://build.opensuse.org/request/show/39394 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/coreutils?expand=0&rev=39
50 lines
1.7 KiB
Diff
50 lines
1.7 KiB
Diff
While uid_t and gid_t are both unsigned, the values (uid_t) -1 and
|
|
(gid_t) -1 are reserved. A uid or gid argument of -1 to the chown(2)
|
|
system call means to leave the uid/gid unchanged. Catch this case
|
|
so that trying to set a uid or gid to -1 will result in an error.
|
|
|
|
Test cases:
|
|
|
|
chown 4294967295 file
|
|
chown :4294967295 file
|
|
chgrp 4294967295 file
|
|
|
|
Andreas Gruenbacher <agruen@suse.de>
|
|
|
|
Index: lib/userspec.c
|
|
===================================================================
|
|
--- lib/userspec.c.orig 2010-05-04 17:27:48.479359439 +0200
|
|
+++ lib/userspec.c 2010-05-04 17:29:12.439359267 +0200
|
|
@@ -169,7 +169,7 @@ parse_with_separator (char const *spec,
|
|
{
|
|
unsigned long int tmp;
|
|
if (xstrtoul (u, NULL, 10, &tmp, "") == LONGINT_OK
|
|
- && tmp <= MAXUID)
|
|
+ && tmp <= MAXUID && tmp != (uid_t) -1)
|
|
unum = tmp;
|
|
else
|
|
error_msg = E_invalid_user;
|
|
@@ -200,7 +200,8 @@ parse_with_separator (char const *spec,
|
|
if (grp == NULL)
|
|
{
|
|
unsigned long int tmp;
|
|
- if (xstrtoul (g, NULL, 10, &tmp, "") == LONGINT_OK && tmp <= MAXGID)
|
|
+ if (xstrtoul (g, NULL, 10, &tmp, "") == LONGINT_OK && tmp <= MAXGID
|
|
+ && tmp != (gid_t) -1)
|
|
gnum = tmp;
|
|
else
|
|
error_msg = E_invalid_group;
|
|
Index: src/chgrp.c
|
|
===================================================================
|
|
--- src/chgrp.c.orig 2010-05-04 17:27:48.479359439 +0200
|
|
+++ src/chgrp.c 2010-05-04 17:29:12.443359269 +0200
|
|
@@ -89,7 +89,7 @@ parse_group (const char *name)
|
|
{
|
|
unsigned long int tmp;
|
|
if (! (xstrtoul (name, NULL, 10, &tmp, "") == LONGINT_OK
|
|
- && tmp <= GID_T_MAX))
|
|
+ && tmp <= GID_T_MAX && tmp != (gid_t) -1))
|
|
error (EXIT_FAILURE, 0, _("invalid group: %s"), quote (name));
|
|
gid = tmp;
|
|
}
|