From owner-svn-src-all@freebsd.org Fri Jun 23 00:36:52 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ECE22D98623; Fri, 23 Jun 2017 00:36:52 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-pf0-f170.google.com (mail-pf0-f170.google.com [209.85.192.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BCDA571123; Fri, 23 Jun 2017 00:36:52 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-pf0-f170.google.com with SMTP id s66so16044117pfs.1; Thu, 22 Jun 2017 17:36:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=wO13HNJfNQ0d0BC0THVaZwl9o1u1b5jhX8VIFkZoPBk=; b=e4RPhnIH/DIMfUCmVwTXKLeeHwBj7h8A2uDAE77IxzlcbDMXAYCXZnazO+LP31a2JS nUl6LVNcDmFUb/GdeI11j4tQ9BKFqVWY3j4TnAi0OKunGXBQxSMmyKOCBn73fc6YkX+x rMEVaoyFwPuSit97Nzyk6bDZ4Xtipg0LU2/htch/HeFQ78DtYwT/aXDvou7V5PEKHzTi lP+fpG7Ee4UpvDPi/PD8d7tcyeHXqEFiCHMvAw/mCu1qnD0Z+o6PrOPqMx24o3R2+8lM /Ko/U/JTS1RqJw3FG9njLvuS5RMs8z++yAkIVkFKQZ50VbRs8VjRZe/o10PTfyelQEp/ cqGA== X-Gm-Message-State: AKS2vOw77puXMpSL8Q54qlaPTpzPcWX/Zc3ND6jiVeHj+jr7vlnjbbLY H48aI+aT1d9X+l55hQ+vmw== X-Received: by 10.98.192.204 with SMTP id g73mr5248932pfk.26.1498176783648; Thu, 22 Jun 2017 17:13:03 -0700 (PDT) Received: from mail-pg0-f43.google.com (mail-pg0-f43.google.com. [74.125.83.43]) by smtp.gmail.com with ESMTPSA id s29sm5941084pfi.17.2017.06.22.17.13.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jun 2017 17:13:03 -0700 (PDT) Received: by mail-pg0-f43.google.com with SMTP id f127so14356394pgc.0; Thu, 22 Jun 2017 17:13:03 -0700 (PDT) X-Received: by 10.99.119.12 with SMTP id s12mr5284842pgc.143.1498176783357; Thu, 22 Jun 2017 17:13:03 -0700 (PDT) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 10.100.133.66 with HTTP; Thu, 22 Jun 2017 17:13:02 -0700 (PDT) In-Reply-To: <201706170258.v5H2wWCT006080@repo.freebsd.org> References: <201706170258.v5H2wWCT006080@repo.freebsd.org> From: Conrad Meyer Date: Thu, 22 Jun 2017 17:13:02 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r320048 - head/usr.bin/mkuzip To: Maxim Sobolev Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jun 2017 00:36:53 -0000 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, &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); > +}