Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Apr 2017 11:30:08 -0700
From:      Maxim Sobolev <sobomax@freebsd.org>
To:        "Conrad E. Meyer" <cem@freebsd.org>
Cc:        src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r316718 - head/sbin/mksnap_ffs
Message-ID:  <CAH7qZfub=jsu2YYmr=g=ZHnidZ66-YMaiqv1_W1sz0huU7V%2Bdw@mail.gmail.com>
In-Reply-To: <CAG6CVpWDxgmON2ELcdOygCkQd29esCdYHoQUP2b948wA3x5JEw@mail.gmail.com>
References:  <201704112155.v3BLtepk065823@repo.freebsd.org> <CAG6CVpWDxgmON2ELcdOygCkQd29esCdYHoQUP2b948wA3x5JEw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Ah, that's right. Good catch, sorry about that. I will fix it momentarily.

-Maxim

On Wed, Apr 12, 2017 at 8:51 AM, Conrad Meyer <cem@freebsd.org> wrote:

> Hi Maxim,
>
> This breaks several stbuf checks in main() following the stat() call
> you removed to isdir().  Coverity reported this as CID 1374247.
>
> On Tue, Apr 11, 2017 at 2:55 PM, Maxim Sobolev <sobomax@freebsd.org>
> wrote:
> > Author: sobomax
> > Date: Tue Apr 11 21:55:39 2017
> > New Revision: 316718
> > URL: https://svnweb.freebsd.org/changeset/base/316718
> >
> > ...
> > --- head/sbin/mksnap_ffs/mksnap_ffs.c   Tue Apr 11 20:28:15 2017
> (r316717)
> > +++ head/sbin/mksnap_ffs/mksnap_ffs.c   Tue Apr 11 21:55:39 2017
> (r316718)
> > @@ -58,6 +58,33 @@ usage(void)
> >         errx(EX_USAGE, "usage: mksnap_ffs snapshot_name");
> >  }
> >
> > +static int
> > +isdir(const char *path)
> > +{
> > +       struct stat stbuf;
> > +
> > +       if (stat(path, &stbuf) < 0)
> > +               return (-1);
>                 ^^^^^^^^^^^^^^^^^^ moved here
>
> > +        if (!S_ISDIR(stbuf.st_mode))
> > +               return (0);
> > +       return (1);
> > +}
> > ...
> > @@ -96,16 +123,33 @@ main(int argc, char **argv)
> >         }
> >         if (statfs(path, &stfsbuf) < 0)
> >                 err(1, "%s", path);
> > -       if (stat(path, &stbuf) < 0)
>           ^^^^^^^^^^^^^^^^^^^ from here
>
> > +       switch (isdir(path)) {
> > +       case -1:
> >                 err(1, "%s", path);
> > -       if (!S_ISDIR(stbuf.st_mode))
> > +       case 0:
> >                 errx(1, "%s: Not a directory", path);
> > +       default:
> > +               break;
> > +       }
> >         if (access(path, W_OK) < 0)
> >                 err(1, "Lack write permission in %s", path);
> >         if ((stbuf.st_mode & S_ISTXT) && stbuf.st_uid != getuid())
>                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ now uninitialized use
>
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAH7qZfub=jsu2YYmr=g=ZHnidZ66-YMaiqv1_W1sz0huU7V%2Bdw>