Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BAC81C433FE for ; Wed, 23 Nov 2022 07:55:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 45E108521C; Wed, 23 Nov 2022 08:55:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de 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; secure) header.d=gmx.de header.i=@gmx.de header.b="LoLFh/ZE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A70458521E; Wed, 23 Nov 2022 08:55:32 +0100 (CET) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AC0948521B for ; Wed, 23 Nov 2022 08:55:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669190129; bh=U/Jiahs9avR3mv3Hk8lY7WNOFDF89aW/Q+JXGUqESNk=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=LoLFh/ZEqJztulsjY0KizFLHM7zlUIcWYMey5B+WNDO4kB34oM/9gnprj9Fjtg30D 7y8JgnX7Df02+Vx38PKBsIs4tKiJVNq8day2V7Wjpt2VYAjcpYs6hAq3o8klgAaQT1 a46riy5vpdoGmZ5Gp2EeahHRnNadyw8xHLJ2pm3jw1lQJwMBHctMXF2ToTcPTp5Dn4 hDvr4vit4KL8qpFYKuMnE2MikcAtLB667TmX4Ac95+hcn7CUaINk2jhF/KuZuEq+1S TZSE4T6I+6wC89dKWzTRBc9JvRT8ksBbrnqyEliYRSNa5dgs9pf1UnIsVz3FIux0Yb P7LXVLIUBxMZw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.123.94] ([84.118.157.2]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N8XPt-1p1gUC0wjZ-014Wzx; Wed, 23 Nov 2022 08:55:29 +0100 Message-ID: Date: Wed, 23 Nov 2022 08:55:28 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v2] tools: mkimage: Fix nullptr at strchr() Content-Language: en-US To: Mikhail Ilin Cc: u-boot@lists.denx.de, Simon Glass References: <20221123071021.10286-1-ilin.mikhail.ol@gmail.com> From: Heinrich Schuchardt In-Reply-To: <20221123071021.10286-1-ilin.mikhail.ol@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:HJsMgdOM/obMn4KsS9q4KG8CPGFDFUsGHofRpSNhPTNy4Pj+mph jTw5tkNb4fryIOuFMTEbRD4a1W0j+veprEtEpIPRZIPvog6mV5nyN3Le3Ix1q5JgZrGECvV O9p1vteYtn8UUzozdaZVwDw4yHFTbxM/zj1yI7F8Z6JEm0WtJJuqIIwXLyQby7+kJva0RAt dPgSlcGN1mNZYQU1Ako/A== UI-OutboundReport: notjunk:1;M01:P0:KdjF/TCxgtA=;6dOii+Emgt7OY3ykwjrOJ2BLoeO sGXvIjyXpNqasCjBcJp86qghNUD830vVJmfegUgQBz9wGfMJaqPrxuqtAxtstNglm6YZRL036 JSfNBq45u/md1BiwKMN3+17dT/H+FhiAnpDg4Z767HN9G3wrMLcyqvcMMn//QBwXhNymh1o+p RwRe5wNz28axVZOktPN4gh1wAgfaJ6xHiWghA2XigyuisKWXhgu3Rn/1+Subb2y6qKu/Q5msG JtU6MJ0ae6rCxeWAMSCLNMdFPK3nc1nUpWrLBK6H7xGpXuYMDfttZTfSAY4T0jOjZo+kSD8uz sF1L4ExJjM19ZahtA0HTv6+HLaXKb5DqmMuOzBSAU0Sd85M+j8NzPQFwWvNm3Cyv29cEw7+11 +P2Ya90PEIvNLBypfNLcJNsxBTaScNQP5lLjIAzt9BJc+e2SDCldphGeznJgLuF1QkY3HU2qv 9YBYDNHj/v+EALZ5CAitYMS2aeHPYnWb15xoJhfUwdGngVrItjeeUAYeMnpZl9ixly1IS6np1 F8CrEJj2NRZtVlDOJrfqRBzr2CZaOc8hnenXPs9M9tl0MRzDCC2rADKg32UOnTP7sr9zYxtxf YyGeF9FcPCiZ6D1bmvtFLmdMqznEjpCSVaeU41pNwPCnywwS/v8nFz5qeo0s/pXN4PP9emvcU +yqQvlVd9oLbkPs0U3rHxBMZN+PcNT6s9Q8F9w3Btr0DU6R0li6wDf2jLjfB9CnG7VPhNkt0m iw4Z3JewuLW7KFkIYN1aje25QhBHCS1GKcZJ/vJkviPlPZoVmPuJOZww2xrSBPG7BIrUziW6X 2ysMcGgEmlTTiUrSSdNltaxV3gISAgpqMr9KtAS+ir80QUe7+Bm8rGGDelfwCO0zOi66YnoZ1 KbuTHXuU8SvE1PiyOkXOwpxwR6ta4T7KQ+ggoet52oz9C7Cf5ZRtHdTyMaqzua7tje2A39/7t nTHrmw== 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.6 at phobos.denx.de X-Virus-Status: Clean On 11/23/22 08:10, Mikhail Ilin wrote: > The 'file' pointer can be null. Thus, before using it in the > strchr() function, you need to make sure that it is not null. > > Fixes: d1be8f922eb3 ("mkimage: Fix variable length header support") > Signed-off-by: Mikhail Ilin > --- > tools/mkimage.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tools/mkimage.c b/tools/mkimage.c > index 5f51d2cc89..95005d8414 100644 > --- a/tools/mkimage.c > +++ b/tools/mkimage.c > @@ -509,6 +509,8 @@ int main(int argc, char **argv) > file =3D params.datafile; > > for (;;) { > + if (!file) > + break; The main function is now 370 lines long. It really should be restructured into smaller functions to make it readable. I would prefer if you would pull out a function copy_datafile(ifd, params.datafile) for copying the data file. > char *sep =3D strchr(file, ':'); We don't want variable definitions in the middle of the code. Please, move the declaration to the top of the code block. Best regards Heinrich > if (sep) { > *sep =3D '\0';