svn commit: r316718 - head/sbin/mksnap_ffs

Conrad Meyer cem at freebsd.org
Wed Apr 12 16:00:01 UTC 2017


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 at 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


More information about the svn-src-all mailing list