diff options
author | Jim Meyering <jim@meyering.net> | 1995-06-25 01:44:35 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1995-06-25 01:44:35 +0000 |
commit | 9a5882ba8068d5e13daebac92d94021fe7b43935 (patch) | |
tree | 921ce32ff43ce56d68555b849dc7d99d3e0e564d /src/chgrp.c | |
parent | 7981e85eb3546acb2d4d6cd634330d8581ecc9de (diff) | |
download | coreutils-9a5882ba8068d5e13daebac92d94021fe7b43935.tar.xz |
(parse_group): Use xstrtoul instead of isnumber; the latter would
silently overflow, accepting a group id larger than INT_MAX.
(isnumber): Remove now-unused static function.
(change_file_group) [MAXUID]: Give a more descriptive message
when numeric group id is larger than MAXUID.
Diffstat (limited to 'src/chgrp.c')
-rw-r--r-- | src/chgrp.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/chgrp.c b/src/chgrp.c index a3907238d..b5e62b665 100644 --- a/src/chgrp.c +++ b/src/chgrp.c @@ -25,6 +25,7 @@ #include "system.h" #include "version.h" +#include "xstrtoul.h" #include "error.h" #ifndef _POSIX_VERSION @@ -42,7 +43,6 @@ char *xrealloc (); static int change_file_group (); static int change_dir_group (); -static int isnumber (); static void describe_change (); static void parse_group (); static void usage (); @@ -159,9 +159,15 @@ parse_group (name, g) grp = getgrnam (name); if (grp == NULL) { - if (!isnumber (name)) - error (1, 0, "invalid group `%s'", name); - *g = atoi (name); + strtol_error s_err; + unsigned long int tmp_long; + + s_err = xstrtoul (name, NULL, 0, &tmp_long, NULL); + *g = tmp_long; + if (s_err == LONGINT_OVERFLOW || tmp_long > INT_MAX) + { + STRTOL_FATAL_ERROR (name, "group number", s_err); + } } else *g = grp->gr_gid; @@ -204,6 +210,12 @@ change_file_group (file, group) error (0, errno, "you are not a member of group `%s'", groupname); } +#ifdef MAXUID + else if (errno == EINVAL && group > MAXUID) + { + error (0, 0, "%s: invalid group number", groupname); + } +#endif else { error (0, errno, "%s", file); @@ -288,19 +300,6 @@ describe_change (file, changed) printf ("group of %s retained as %s\n", file, groupname); } -/* Return nonzero if STR represents an unsigned decimal integer, - otherwise return 0. */ - -static int -isnumber (str) - char *str; -{ - for (; *str; str++) - if (!ISDIGIT (*str)) - return 0; - return 1; -} - static void usage (status) int status; |