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 733ADCE8D6B for ; Mon, 17 Nov 2025 10:55:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CE682839A8; Mon, 17 Nov 2025 11:55:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (4096-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="OKEWjQh+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7519283A79; Mon, 17 Nov 2025 11:55:37 +0100 (CET) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (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 16A81839A1 for ; Mon, 17 Nov 2025 11:55:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id F04123F628 for ; Mon, 17 Nov 2025 10:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1763376933; bh=asJZRBw3lJV+AlcomqG6mn8aYteBHBxsdFQmH15RjTs=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=OKEWjQh+3F3s2RpxLcRBtvMYdV/9ZDOvmJKZBsD//4o6KI5T5K1DnIgwQckTeTWpE rMPo6cn8Ezzfn1Wvv9q0eoDcbSVF5iI+iUAmK4x2/IwmP8FBvzygVTXekfhPbggEuv XbmN/SzWECuANf2BkymRpjUZdSm3IBur/FlqYXkLKTEmRTi/Y5Ioylhok7uG5jnasi 7LBiZUQzxW8BcS6vn7/30BEGoBtSQA9BL6Eq/QBOQqw7WcBSapbdZpLt5IlswLeagP proYt2/OdNYMowGnHNuwfeaIc0+ghm38aqXefZQE/6MygIneW3X+Xoli3QeXo4MsMp zYJ5ufZzVMUL8ojjfgwzggHsDqu3OjSWZN4hiLa79mzpH4hA0zPSMiE/Vi2wxP/Djn sBPDdp81CLz5e7mdP2KS6joBn4rFCVIPToZcUceaPR4s1zijj4cJfGtdNq4FJL5Tkj 7wrGMKObIFn/LMejYT0iY0/Il4+slnJ2zlSikzA26bMyNPsM0uPG1Bt4jjWjmCknQM FglP0TeXyL67aZgK6W7Lt0zUBOUZQUYAvc8SAogMtWiZCrKaFh+lZj4MkL2Y5jP0BA 63vnJGhbDDyz3DkHidANQtNJy4vx9kb/95PGfvbUInKdVf+LdUd/9P/kV017L2mWJB k8+cwQI8rlbl+G+hK05g+kZQ= Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-42b3086a055so2768981f8f.3 for ; Mon, 17 Nov 2025 02:55:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763376933; x=1763981733; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=asJZRBw3lJV+AlcomqG6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tfT E+IsDOrX8Cwn31DkfRIyPzPUxkcZ80LOlUaTbIqq9cCYfHni5FXksFAs= X-Received: by 2002:a05:6000:4186:b0:429:d19f:d959 with SMTP id ffacd0b85a97d-42b5934d6f1mr10457349f8f.15.1763376933526; Mon, 17 Nov 2025 02:55:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEj3RJypO6RlvOSzOvbYAQDbrraZxZ+1uGhjPxwwYOwI4enEgoGTWe6ShakpW41HCvFFoFanQ== X-Received: by 2002:a05:6000:4186:b0:429:d19f:d959 with SMTP id ffacd0b85a97d-42b5934d6f1mr10457317f8f.15.1763376933095; Mon, 17 Nov 2025 02:55:33 -0800 (PST) Received: from [192.168.103.118] (ip-005-147-080-091.um06.pools.vodafone-ip.de. [5.147.80.91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e7ae5bsm25513651f8f.8.2025.11.17.02.55.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Nov 2025 02:55:32 -0800 (PST) From: Heinrich Schuchardt X-Google-Original-From: Heinrich Schuchardt Message-ID: <86bf47cb-60e2-466a-a471-b08ece0efacd@gmx.de> Date: Mon, 17 Nov 2025 11:55:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] boot: pxe_utils: Fix memory allocation issues in overlay_dir handling To: Kory Maincent Cc: Bajjuri Praneeth , Quentin Schulz , thomas.petazzoni@bootlin.com, Tom Rini , Andrew Goodbody , u-boot@lists.denx.de, Simon Glass References: <20251113093313.362055-1-kory.maincent@bootlin.com> Content-Language: en-US In-Reply-To: <20251113093313.362055-1-kory.maincent@bootlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 On 11/13/25 10:33, Kory Maincent wrote: > From: "Kory Maincent (TI.com)" > > Fix two memory allocation bugs in label_boot_extension(): > > 1. When label->fdtdir is not set, overlay_dir was used without any > memory allocation. > > 2. When label->fdtdir is set, the allocation size was incorrect, > using 'len' (just the fdtdir length) instead of 'dir_len' (which > includes the trailing slash and null terminator). > > Resolve both issues by moving the memory allocation and string > formatting outside the conditional block, resulting in clearer code > flow and correct sizing in all cases. > > Closes: https://lists.denx.de/pipermail/u-boot/2025-November/602892.html > Fixes: 935109cd9e97 ("boot: pxe_utils: Add extension board devicetree overlay support") > Signed-off-by: Kory Maincent (TI.com) Please, add Addresses-Coverity-ID: 638558 Memory - illegal accesses (UNINIT) so that we know that the Coverity issue is resolved. > --- > > Change in v2: > - Extract calloc and snprintf of the if condition. > --- > boot/pxe_utils.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c > index 038416203fc..7549a93bdad 100644 > --- a/boot/pxe_utils.c > +++ b/boot/pxe_utils.c > @@ -473,18 +473,18 @@ static void label_boot_extension(struct pxe_context *ctx, > else > slash = ""; > > - dir_len = strlen(label->fdtdir) + strlen(slash) + 1; > - overlay_dir = calloc(1, len); > - if (!overlay_dir) > - return; > - > - snprintf(overlay_dir, dir_len, "%s%s", label->fdtdir, > - slash); > + dir_len = len + strlen(slash) + 1; This line could be moved after the else branch to simplify the code by avoiding separate assignments to dir_len. Best regards Heinrich > } else { > dir_len = 2; > - snprintf(overlay_dir, dir_len, "/"); > + slash = "/"; > } > > + overlay_dir = calloc(1, dir_len); > + if (!overlay_dir) > + return; > + > + snprintf(overlay_dir, dir_len, "%s%s", label->fdtdir ?: "", slash); > + > alist_for_each(extension, extension_list) { > char *overlay_file; > ulong size;