From mboxrd@z Thu Jan 1 00:00:00 1970 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 2D0F1C64ED8 for ; Mon, 27 Feb 2023 20:03:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3165285C06; Mon, 27 Feb 2023 20:57:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=mailbox.org 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=mailbox.org header.i=@mailbox.org header.b="bmxOxs8d"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="KpwaS8i8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 01DE685BB0; Mon, 27 Feb 2023 20:56:45 +0100 (CET) Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [IPv6:2001:67c:2050:0:465::103]) (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 D4BFE85BB2 for ; Mon, 27 Feb 2023 20:56:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=marek.vasut+renesas@mailbox.org Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4PQWTz4ZBzz9sjZ; Mon, 27 Feb 2023 20:56:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1677527799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ujcVtXmHASkxHxMmCIel3q7Xs58/IlUdZof/duHWM+M=; b=bmxOxs8dLoqMwVTPA/6izLNIpOwoMNWoD7OvruWw3e5HXkRkZpQna1lb2vVI3l6S5gnomq S2g33Nht10RoA6dvpnAtlAghbMN/Q+73xeAc9gxon9NKsuXgoShWH4mFBaOMSQ0OeBRw2v PHNxq3RUPRQgUbniGb+AiSqEEGsU/Ukuh0BuL3dUUom6hBZeiMhIVqbr+C+87jIExe+0bn lhTDzkLN1JQvlJZwOeKZkz+pb+T2FURI2eiEa0dHbZXAdVJHm+lnHgbpPAU9hYFgo8X3s3 rMt8wWa6oDAcZqD0aqVKSaXb0gZFHYs3+a2DLCQxIMlpICA+D3nRG0ToEw9zuQ== From: Marek Vasut DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1677527797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ujcVtXmHASkxHxMmCIel3q7Xs58/IlUdZof/duHWM+M=; b=KpwaS8i895ftLDN+9DBykAZN11333489t24h4eV+bmVQK6LO+SfvTZljrnGp/ZytZHiKab HZDA4JMivxAUkUlItn6843vR5DfRw/QauRpaVJZf6nUxhscsOX1N+Ijgqy1TK+1NYJ9i86 z2Sd0a4O/JLHXuOIq2pe5GfmPwMys+uj2Woeknk9Ogkc/AHRozcrDkPZrdEtwa3A1dnBaW 8ynX2worqOwVMF62PoUemHVwhCYfR2xQKwrEOu+YpUb5IvEIFcj5P3cvoWHxhA7yH9aoKH prOu/1iy8RHhHV/XIsn77T8U+VvmjpTM4ejK7yyK4Zfi8YKOtgOHiSFJYDB51w== To: u-boot@lists.denx.de Cc: Marek Vasut , Heinrich Schuchardt , Michal Simek , Oleksandr Suvorov , Simon Glass , Stefan Roese , Tom Rini Subject: [PATCH] image: Fix potentially uninitialized data variable Date: Mon, 27 Feb 2023 20:56:31 +0100 Message-Id: <20230227195631.98868-1-marek.vasut+renesas@mailbox.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MBO-RS-META: tq7g7aayaz9m95zryeqmdps8wsbihbfk X-MBO-RS-ID: d4c4522e58478fbd99e 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 In case fitImage support is disabled, and image_locate_script() is passed a fitImage, then the 'data' variable is used uninitialized. Drop into the default: branch of the switch-case statement and do not return the uninitialized data, and do not modify the return pointer either, just print an error message. Reported by clang build: " $ make HOSTCC=clang CC=clang KCFLAGS=-Werror sandbox64_defconfig && make HOSTCC=clang CC=clang KCFLAGS=-Werror ... boot/image-board.c:1006:7: error: variable 'data' is used uninitialized whenever switch case is taken [-Werror,-Wsometimes-uninitialized] case IMAGE_FORMAT_LEGACY: ^~~~~~~~~~~~~~~~~~~ include/image.h:608:29: note: expanded from macro 'IMAGE_FORMAT_LEGACY' ^~~~ boot/image-board.c:1128:19: note: uninitialized use occurs here *datap = (char *)data; ^~~~ boot/image-board.c:1001:11: note: initialize the variable 'data' to silence this warning u32 *data; ^ = NULL " Signed-off-by: Marek Vasut --- Cc: Heinrich Schuchardt Cc: Michal Simek Cc: Oleksandr Suvorov Cc: Simon Glass Cc: Stefan Roese Cc: Tom Rini --- boot/image-board.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/boot/image-board.c b/boot/image-board.c index 25b60ec30b3..9bf70824cb7 100644 --- a/boot/image-board.c +++ b/boot/image-board.c @@ -1004,7 +1004,9 @@ int image_locate_script(void *buf, int size, const char *fit_uname, switch (genimg_get_format(buf)) { case IMAGE_FORMAT_LEGACY: - if (IS_ENABLED(CONFIG_LEGACY_IMAGE_FORMAT)) { + if (!IS_ENABLED(CONFIG_LEGACY_IMAGE_FORMAT)) { + goto exit_image_format; + } else { hdr = buf; if (!image_check_magic(hdr)) { @@ -1047,7 +1049,9 @@ int image_locate_script(void *buf, int size, const char *fit_uname, } break; case IMAGE_FORMAT_FIT: - if (IS_ENABLED(CONFIG_FIT)) { + if (!IS_ENABLED(CONFIG_FIT)) { + goto exit_image_format; + } else { fit_hdr = buf; if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) { puts("Bad FIT image format\n"); @@ -1121,12 +1125,15 @@ fallback: } break; default: - puts("Wrong image format for \"source\" command\n"); - return -EPERM; + goto exit_image_format; } *datap = (char *)data; *lenp = len; return 0; + +exit_image_format: + puts("Wrong image format for \"source\" command\n"); + return -EPERM; } -- 2.39.2