Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Apr 2017 08:51:54 -0700
From:      Conrad Meyer <cem@freebsd.org>
To:        Maxim Sobolev <sobomax@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:  <CAG6CVpWDxgmON2ELcdOygCkQd29esCdYHoQUP2b948wA3x5JEw@mail.gmail.com>
In-Reply-To: <201704112155.v3BLtepk065823@repo.freebsd.org>
References:  <201704112155.v3BLtepk065823@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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?CAG6CVpWDxgmON2ELcdOygCkQd29esCdYHoQUP2b948wA3x5JEw>