bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: userspec fixes for coreutils (e.g., "chown 010 file")


From: Dmitry V. Levin
Subject: Re: userspec fixes for coreutils (e.g., "chown 010 file")
Date: Fri, 13 Aug 2004 21:43:08 +0400

Hi,

On Wed, Jul 28, 2004 at 04:10:14PM -0700, Paul Eggert wrote:
> coreutils chown and chgrp mishandle some numeric uids and gids that
> have leading zeros.  For example, "chown 010 file" is treated as
> "chown 8 file", where it should be like "chown 10 file".  I discovered
> this while auditing for integer arithmetic problems, and installed the
> following patch to fix this and do some related minor cleanups for
> integers.
[...]
> @@ -209,23 +217,16 @@ parse_user_spec (const char *spec_arg, u
>        pwd = getpwnam (u);
>        if (pwd == NULL)
>       {
> -
> -       if (!is_number (u))
> -         error_msg = E_invalid_user;
> +       bool use_login_group = (separator != NULL && g == NULL);
> +       if (use_login_group)
> +         error_msg = E_bad_spec;
>         else
>           {
> -           int use_login_group;
> -           use_login_group = (separator != NULL && g == NULL);
> -           if (use_login_group)
> -             error_msg = E_bad_spec;
> -           else
> -             {
> -               unsigned long int tmp_long;
> -               if (xstrtoul (u, NULL, 0, &tmp_long, NULL) != LONGINT_OK
> -                   || tmp_long > MAXUID)
> -                 return _(E_invalid_user);
> -               *uid = tmp_long;
> -             }
> +           unsigned long int tmp_long;
> +           if (! (xstrtoul (u, NULL, 10, &tmp_long, "") == LONGINT_OK
> +                  && tmp_long <= MAXUID))
> +             return _(E_invalid_user);
> +           *uid = tmp_long;
>           }
>       }
>        else

This change introduces regression:

$ chown "`id -u`.`id -g`" .
chown: `567.567': invalid user
$ chown "`id -un`.`id -gn`" .
chown: `me.me': invalid user

Proposed fix along with new testcase is attached.


-- 
ldv

Attachment: coreutils-5.3.0-alt-parse_user_spec.patch
Description: Text document

Attachment: pgpCcu9_ZLdTz.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]