From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:45793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1CiP-0002CN-5V for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:14:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1CiO-0006Fz-Bp for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:14:49 -0500 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]:41030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1CiO-0006FK-3A for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:14:48 -0500 Received: by mail-ot1-x334.google.com with SMTP id t7so7879459otk.8 for ; Tue, 05 Mar 2019 08:14:47 -0800 (PST) MIME-Version: 1.0 References: <20180227083919.12339-1-kraxel@redhat.com> <20180227083919.12339-4-kraxel@redhat.com> In-Reply-To: <20180227083919.12339-4-kraxel@redhat.com> From: Peter Maydell Date: Tue, 5 Mar 2019 16:14:34 +0000 Message-ID: Content-Type: text/plain; charset="UTF-8" Subject: Re: [Qemu-devel] [PULL 3/5] usb-mtp: Support delete of mtp objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: QEMU Developers , Bandan Das On Tue, 27 Feb 2018 at 08:41, Gerd Hoffmann wrote: > > From: Bandan Das > > Write of existing objects by the initiator is acheived by > making a temporary buffer with the new changes, deleting the > old file and then writing a new file with the same name. > > Also, add a "readonly" property which needs to be set to false > for deletion to work. Hi -- Coverity points out a use-after-free here (CID 1399144): > +static int usb_mtp_deletefn(MTPState *s, MTPObject *o, uint32_t trans) > +{ > + MTPObject *iter, *iter2; > + bool partial_delete = false; > + bool success = false; > + > + /* > + * TODO: Add support for Protection Status > + */ > + > + QLIST_FOREACH(iter, &o->children, list) { > + if (iter->format == FMT_ASSOCIATION) { > + QLIST_FOREACH(iter2, &iter->children, list) { > + usb_mtp_deletefn(s, iter2, trans); > + } > + } > + } > + > + if (o->format == FMT_UNDEFINED_OBJECT) { > + if (remove(o->path)) { > + partial_delete = true; > + } else { > + usb_mtp_object_free_one(s, o); This call will call g_free(o)... > + success = true; > + } > + } > + > + if (o->format == FMT_ASSOCIATION) { ...but flow of control then falls through to here, where we try to access o->format. Preusumably this should be an "else if" clause ? > + if (rmdir(o->path)) { > + partial_delete = true; > + } else { > + usb_mtp_object_free_one(s, o); > + success = true; > + } > + } > + > + if (success && partial_delete) { > + return PARTIAL_DELETE; > + } > + if (!success && partial_delete) { > + return READ_ONLY; > + } > + return ALL_DELETE; > +} > + thanks -- PMM