Re: svn commit: r320048 - head/usr.bin/mkuzip

2017-06-23 Thread Maxim Sobolev
Sorry overlooked that. Fixed, thanks!

-Maxim

On Thu, Jun 22, 2017 at 5:13 PM, Conrad Meyer  wrote:

> ffd is leaked in return paths.  Coverity CID 1376420.
>
> On Fri, Jun 16, 2017 at 7:58 PM, Maxim Sobolev 
> 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, ) != 0) {
> > +   warn("fstat(%s)", cfp->iname);
> > +   return (-1);
> > +   }
> > +   if ((sb.st_flags & SF_SNAPSHOT) != 0) {
> > +   if (fstatfs(cfp->fdr, ) != 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, ) < 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, ) < 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"


Re: svn commit: r320048 - head/usr.bin/mkuzip

2017-06-22 Thread Conrad Meyer
ffd is leaked in return paths.  Coverity CID 1376420.

On Fri, Jun 16, 2017 at 7:58 PM, Maxim Sobolev  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, ) != 0) {
> +   warn("fstat(%s)", cfp->iname);
> +   return (-1);
> +   }
> +   if ((sb.st_flags & SF_SNAPSHOT) != 0) {
> +   if (fstatfs(cfp->fdr, ) != 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, ) < 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, ) < 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"


svn commit: r320048 - head/usr.bin/mkuzip

2017-06-16 Thread Maxim Sobolev
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   (contents, props changed)
  head/usr.bin/mkuzip/mkuz_insize.h   (contents, props changed)
Modified:
  head/usr.bin/mkuzip/Makefile
  head/usr.bin/mkuzip/mkuz_cfg.h
  head/usr.bin/mkuzip/mkuzip.c

Modified: head/usr.bin/mkuzip/Makefile
==
--- head/usr.bin/mkuzip/MakefileSat Jun 17 01:27:15 2017
(r320047)
+++ head/usr.bin/mkuzip/MakefileSat Jun 17 02:58:31 2017
(r320048)
@@ -3,7 +3,7 @@
 PROG=  mkuzip
 MAN=   mkuzip.8
 SRCS=  mkuzip.c mkuz_blockcache.c mkuz_lzma.c mkuz_zlib.c mkuz_conveyor.c \
-   mkuz_blk.c mkuz_fqueue.c mkuz_time.c
+   mkuz_blk.c mkuz_fqueue.c mkuz_time.c mkuz_insize.c
 
 #CFLAGS+=  -DMKUZ_DEBUG
 

Modified: head/usr.bin/mkuzip/mkuz_cfg.h
==
--- head/usr.bin/mkuzip/mkuz_cfg.h  Sat Jun 17 01:27:15 2017
(r320047)
+++ head/usr.bin/mkuzip/mkuz_cfg.h  Sat Jun 17 02:58:31 2017
(r320048)
@@ -36,5 +36,7 @@ struct mkuz_cfg {
 int en_dedup;
 int nworkers;
 int blksz;
+const char *iname;
+off_t isize;
 const struct mkuz_format *handler;
 };

Added: head/usr.bin/mkuzip/mkuz_insize.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.bin/mkuzip/mkuz_insize.c   Sat Jun 17 02:58:31 2017
(r320048)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2004-2016 Maxim Sobolev 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mkuz_cfg.h"
+#include "mkuz_insize.h"
+
+off_t
+mkuz_get_insize(struct mkuz_cfg *cfp)
+{
+   int ffd;
+   off_t ms;
+   struct stat sb;
+   struct statfs statfsbuf;
+
+   if (fstat(cfp->fdr, ) != 0) {
+   warn("fstat(%s)", cfp->iname);
+   return (-1);
+   }
+   if ((sb.st_flags & SF_SNAPSHOT) != 0) {
+   if (fstatfs(cfp->fdr, ) != 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, ) < 0) {
+   warn("ioctl(DIOCGMEDIASIZE)");
+   return (-1);
+   }
+   sb.st_size = ms;
+   } else if (S_ISCHR(sb.st_mode)) {
+   if (ioctl(cfp->fdr, DIOCGMEDIASIZE, ) < 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);
+}

Added: head/usr.bin/mkuzip/mkuz_insize.h