ffd is leaked in return paths.  Coverity CID 1376420.

On Fri, Jun 16, 2017 at 7:58 PM, Maxim Sobolev <sobo...@freebsd.org> wrote:
> Author: sobomax
> Date: Sat Jun 17 02:58:31 2017
> New Revision: 320048
> URL: https://svnweb.freebsd.org/changeset/base/320048
>
> Log:
>   o Move logic that determines size of the input image into its own
>     file. That logic has grown quite significantly now;
>
>   o add a special handling for the snapshot images. Those have some
>     extra headers at the end of the image and we don't need those
>     in the output image really.
>
>   MFC after:    6 weeks
>
> ...
> Added: head/usr.bin/mkuzip/mkuz_insize.c
> ...
> +off_t
> +mkuz_get_insize(struct mkuz_cfg *cfp)
> +{
> +       int ffd;
> +       off_t ms;
> +       struct stat sb;
> +       struct statfs statfsbuf;
> +
> +       if (fstat(cfp->fdr, &sb) != 0) {
> +               warn("fstat(%s)", cfp->iname);
> +               return (-1);
> +       }
> +       if ((sb.st_flags & SF_SNAPSHOT) != 0) {
> +               if (fstatfs(cfp->fdr, &statfsbuf) != 0) {
> +                       warn("fstatfs(%s)", cfp->iname);
> +                       return (-1);
> +               }
> +               ffd = open(statfsbuf.f_mntfromname, O_RDONLY);
> +               if (ffd < 0) {
> +                       warn("open(%s, O_RDONLY)", statfsbuf.f_mntfromname);
> +                       return (-1);
> +               }
> +               if (ioctl(ffd, DIOCGMEDIASIZE, &ms) < 0) {
> +                       warn("ioctl(DIOCGMEDIASIZE)");
> +                       return (-1);

ffd leaked here.

> +               }

ffd also leaked here via fallthrough return.

> +               sb.st_size = ms;
> +       } else if (S_ISCHR(sb.st_mode)) {
> +               if (ioctl(cfp->fdr, DIOCGMEDIASIZE, &ms) < 0) {
> +                       warn("ioctl(DIOCGMEDIASIZE)");
> +                       return (-1);
> +               }
> +               sb.st_size = ms;
> +       } else if (!S_ISREG(sb.st_mode)) {
> +               warnx("%s: not a character device or regular file\n",
> +                       cfp->iname);
> +               return (-1);
> +       }
> +       return (sb.st_size);
> +}
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to