From patchwork Tue May 7 17:30:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 242432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 14CE62C017D for ; Wed, 8 May 2013 03:56:50 +1000 (EST) Received: from localhost ([::1]:60804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZm88-0003cS-Cq for incoming@patchwork.ozlabs.org; Tue, 07 May 2013 13:56:48 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZm7p-0003cD-Rq for qemu-devel@nongnu.org; Tue, 07 May 2013 13:56:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZm7o-00047e-F0 for qemu-devel@nongnu.org; Tue, 07 May 2013 13:56:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZm7o-00047Z-6t for qemu-devel@nongnu.org; Tue, 07 May 2013 13:56:28 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r47HuQUM018110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 7 May 2013 13:56:26 -0400 Received: from [10.3.113.86] (ovpn-113-86.phx2.redhat.com [10.3.113.86]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r47HUA78025760; Tue, 7 May 2013 13:30:18 -0400 Message-ID: <51893A22.1040105@redhat.com> Date: Tue, 07 May 2013 11:30:10 -0600 From: Eric Blake Organization: Red Hat, Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130402 Thunderbird/17.0.5 MIME-Version: 1.0 To: Laszlo Ersek References: <518923DA.6030105@redhat.com> <1367945808-19979-2-git-send-email-lersek@redhat.com> In-Reply-To: <1367945808-19979-2-git-send-email-lersek@redhat.com> X-Enigmail-Version: 1.5.1 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH 2/2] qga: try to unlink just created guest-file if fchmod() fails on it X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On 05/07/2013 10:56 AM, Laszlo Ersek wrote: > We shouldn't allow guest filesystem pollution on error paths. > > Suggested-by: Eric Blake > Signed-off-by: Laszlo Ersek > --- > qga/commands-posix.c | 1 + > 1 files changed, 1 insertions(+), 0 deletions(-) > > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index 2eec712..d301b1f 100644 > --- a/qga/commands-posix.c > +++ b/qga/commands-posix.c > @@ -341,6 +341,7 @@ safe_open_or_create(const char *path, const char *mode, Error **err) > error_setg_errno(&local_err, errno, "failed to set permission " > "0%03o on new file '%s' (mode: '%s')", > (unsigned)DEFAULT_NEW_FILE_MODE, path, mode); > + unlink(path); This fixes the case of a mode 0000 file if fchmod fails, but doesn't fix the case of a mode 0666 file if fchmod succeeds but fdopen fails. It also requires that unlink() while open works (true for most Unix systems, but false for Windows systems and not required by POSIX - but see my realization on 1/2 that this file isn't compiled on Windows). I think you want this instead: diff --git i/qga/commands-posix.c w/qga/commands-posix.c index 04c6951..89cc6d8 100644 --- i/qga/commands-posix.c +++ w/qga/commands-posix.c @@ -345,6 +345,9 @@ safe_open_or_create(const char *path, const char *mode, Error **err) } close(fd); + if (oflag & O_CREAT) { + unlink(path); + } } }