From patchwork Tue May 31 07:15:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 577441 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:330b:0:0:0:0 with SMTP id f11csp888800mag; Tue, 31 May 2022 00:16:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHkDuuphyrBdL4Dtwvd0FmRoELsvEXVMvJkTa8kAwo0LC6PIYdFdAuDzlm6TyoBsXrxs4K X-Received: by 2002:a5e:c307:0:b0:668:b809:ecbb with SMTP id a7-20020a5ec307000000b00668b809ecbbmr3298089iok.174.1653981379262; Tue, 31 May 2022 00:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653981379; cv=none; d=google.com; s=arc-20160816; b=yJ3fx6zbVjGI2d8UE8VscOmHmOXvge+vQVs+/Glrvb9vU9Z/C1aNlUP2lV2O0BZs3J rjp+kFCIQj1YoM027yVZvkMA5VEwf7d8kwV+b56GL6jQwZLiP6fQkWM4K38ZQTOCjKt5 4BV7Z58JiOkU86kSTGmNVjOHwGYIVyfr34a/btxWYoO+QJxZq13YtnRH1WuKN/sJMLI+ 7M+GFmarkONX7yDP3QdsyRxb8XGdpSGbFgqsPKcvtR/UnoRp3UO7CYPmV9vhK4g2q3f7 c0ThpDWRrHi0KPsa9ZR76jeOpz0V52RGb5JBklr7Y2LL3Sm5ITA107Z/Ru3DNT4KggFf VCGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=rXZVLxq+bONecCUkOz1xYPsxijKBAAnKf8pN7Rk25S4=; b=iKtORYOED27XALEM7PepSkP/4IKb6uWLj56OrCEOOCs2od5MIJ61DdEisVALTXUURi aB2nwNoR8ffoJ1iBS3S0je6Sbo1PpWGmxqFtpJy6PvtaaiAS6V/Bkfxair5i5RlRbgZV eHyaJf0UVLzSAU99qGmRHqdBgfNZmpKEvO2IqA0sX9QM/1ZJQSyWcDYLzoNAtDy6Eddf ybuFdWjv2Ywrh+UKZJ8KV50w+lM7nMJkOS4H1vzuSr82pw9x8p0QqiX3p1/9kgbXAkIY 8q4wYxyPkRcD5OUS80s/mzWajqzl1g3qf4GpixQiIRUZD+Xm4eCZcbwnKvA0zMlK9ldv QcvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id i17-20020a925411000000b002d1b63b4b49si10067608ilb.136.2022.05.31.00.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 00:16:19 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F24368437D; Tue, 31 May 2022 09:16:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id DBA1B843DE; Tue, 31 May 2022 09:15:58 +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=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 44325842FE for ; Tue, 31 May 2022 09:15:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92D0223A; Tue, 31 May 2022 00:15:55 -0700 (PDT) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D81793F766; Tue, 31 May 2022 00:15:53 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Takahiro Akashi , Sughosh Ganu Subject: [PATCH 1/3] EFI: Populate descriptor_count value only when image_info_size is not zero Date: Tue, 31 May 2022 12:45:33 +0530 Message-Id: <20220531071535.219661-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220531071535.219661-1-sughosh.ganu@linaro.org> References: <20220531071535.219661-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean The GetImageInfo function of the Firmware Mangement Protocol(FMP) gets called initially to query the size of the image descriptor array that would have to be allocated. During this call, the rest of the function arguments, specifically pointers might be passed as NULL. Do not populate the descriptor_count value before it is known that the call to GetImageInfo has been made with the allocated buffer for the image descriptors. Signed-off-by: Sughosh Ganu Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_firmware.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 27953fe769..6290ca0190 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -130,9 +130,6 @@ static efi_status_t efi_fill_image_desc_array( struct efi_fw_image *fw_array; int i; - fw_array = update_info.images; - *descriptor_count = num_image_type_guids; - total_size = sizeof(*image_info) * num_image_type_guids; if (*image_info_size < total_size) { @@ -142,6 +139,8 @@ static efi_status_t efi_fill_image_desc_array( } *image_info_size = total_size; + fw_array = update_info.images; + *descriptor_count = num_image_type_guids; *descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION; *descriptor_size = sizeof(*image_info); *package_version = 0xffffffff; /* not supported */