Re: [hackers] [PATCH v2 2/2][sbase] chgrp: parse gid if operand is not group name
On Wed, Jul 03, 2019 at 10:44:57PM -0700, Michael Forney wrote:
> On 2019-07-03, Richard Ipsum <richardipsum_AT_fastmail.co.uk> wrote:
[snip]
> >
> > _AT_@ -66,14 +67,21 @@ main(int argc, char *argv[])
> > if (argc < 2)
> > usage();
> >
> > - errno = 0;
> > - if (!(gr = getgrnam(argv[0]))) {
> > - if (errno)
> > - eprintf("getgrnam %s:", argv[0]);
> > - else
> > - eprintf("getgrnam %s: no such group\n", argv[0]);
> > + group = argv[0];
> > + if (group && *group) {
>
> I don't think you need to check if group != NULL here, since we know
> argc >= 2 at this point.
>
> Also, do we need to check *group? Is it an error to call getgrnam(3)
> with an empty string? I assume it would just fail to find a group.
Forgot to mention that I just took this from chown pretty much.
I'm not convinced the checks are needed there either, without the checks
you'll just get an error instead of a usage message.
Thanks,
Richard
Received on Fri Jul 05 2019 - 17:55:31 CEST
This archive was generated by hypermail 2.3.0
: Fri Jul 05 2019 - 18:00:24 CEST