From patchwork Sun Jun 16 13:34:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kurbanov X-Patchwork-Id: 1948364 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=salutedevices.com header.i=@salutedevices.com header.a=rsa-sha256 header.s=mail header.b=uowKKRx9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2cq01C84z20Wg for ; Mon, 17 Jun 2024 14:49:00 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6B46288263; Mon, 17 Jun 2024 06:48:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=salutedevices.com header.i=@salutedevices.com header.b="uowKKRx9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 45E6D87B30; Sun, 16 Jun 2024 15:34:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0BEDB880F5 for ; Sun, 16 Jun 2024 15:34:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mmkurbanov@salutedevices.com Received: from p-infra-ksmg-sc-msk02.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 80FAD120007; Sun, 16 Jun 2024 16:34:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 80FAD120007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1718544876; bh=paMSZhOwobBj91r0W6Nmdl0CrMWK6S0yGobhzaD2NZw=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=uowKKRx9NyRrX08WDH4bgheD7Vg5eKPwp4vMDcfS39CRl/aj12+UvBHqbc6maXINt hFaaeZSp5Jq8IG9xJ8BymxaRq6EJx3bBTzGf8FDKTsB9uj5T0yaTuvgHBP6DeZ4i91 nkmDyOq7uAZFMDPpAyj5PVoNEM9um5skmQMKGZst9TLuQdpIrRC6HLWP603KwWX0Rq HDGk76qdvTCmkxFvxgmzIFts017Doyx4KTi1upwpoCeY+AHchGJspPqKh4ihIFDZiw Zv0n1QAuqN4E2JtwHgRDZ2T7VqKfNk44WlGA4kfLEQ3MHHbHqAXY5vt8mKYtRVJhYW 6TvLBgxpDCOTA== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Sun, 16 Jun 2024 16:34:36 +0300 (MSK) Received: from CAB-WSD-0004828.sberdevices.ru (100.64.160.123) by p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Sun, 16 Jun 2024 16:34:35 +0300 From: Martin Kurbanov To: Tom Rini , Dmitry Dunaev CC: , , Martin Kurbanov Subject: [PATCH v1 2/2] cmd: ubi: check 'updating' before calling ubi_more_update_data() Date: Sun, 16 Jun 2024 16:34:18 +0300 Message-ID: <20240616133426.123299-3-mmkurbanov@salutedevices.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240616133426.123299-1-mmkurbanov@salutedevices.com> References: <20240616133426.123299-1-mmkurbanov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 185944 [Jun 16 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: mmkurbanov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 20 0.3.20 743589a8af6ec90b529f2124c2bbfc3ce1d2f20f, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1; salutedevices.com:7.1.1; 127.0.0.199:7.1.2; smtp.sberdevices.ru:7.1.1,5.0.1; 100.64.160.123:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/06/16 07:48:00 #25636995 X-KSMG-AntiVirus-Status: Clean, skipped X-Mailman-Approved-At: Mon, 17 Jun 2024 06:48:41 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean If 0 is passed to the 'bytes' parameter in the ubi_start_update(), there is no need to call the ubi_more_update_data(). Otherwise, there will be a double-free of 'vol->upd_buf'. Also check that the ubi_start_update() was called before calling the ubi_more_update_data(). Signed-off-by: Martin Kurbanov --- cmd/ubi.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/ubi.c b/cmd/ubi.c index a9c5560182..d252d6387f 100644 --- a/cmd/ubi.c +++ b/cmd/ubi.c @@ -363,6 +363,11 @@ static int ubi_volume_continue_write(char *volume, void *buf, size_t size) if (vol == NULL) return ENODEV; + if (!vol->updating) { + printf("UBI volume update was not initiated\n"); + return EINVAL; + } + err = ubi_more_update_data(ubi, vol, buf, size); if (err < 0) { printf("Couldnt or partially wrote data\n"); @@ -412,6 +417,10 @@ int ubi_volume_begin_write(char *volume, void *buf, size_t size, return -err; } + /* The volume is just wiped out */ + if (!full_size) + return 0; + return ubi_volume_continue_write(volume, buf, size); }