From patchwork Wed Apr 5 08:59:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1765317 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=QImAE/yi; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Prz9D3J09z1yZh for ; Wed, 5 Apr 2023 19:00:00 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6BB4484D00; Wed, 5 Apr 2023 10:59:54 +0200 (CEST) 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 (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="QImAE/yi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1BE7785E72; Wed, 5 Apr 2023 10:59:53 +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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) (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 1706D815D4 for ; Wed, 5 Apr 2023 10:59:50 +0200 (CEST) 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 workstation5.fritz.box (ip-088-152-145-137.um26.pools.vodafone-ip.de [88.152.145.137]) (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-canonical-0.canonical.com (Postfix) with ESMTPSA id 5D35C40DB7; Wed, 5 Apr 2023 08:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1680685189; bh=BjZCiJiEH3IrP+n6jMJSXBuMtcpvyoVTWyTrMX3n6u0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=QImAE/yi4Rjmyc34sBVySFen8P6y7TSl8lmUl6+p/lAsxhZseEDj+NKo8wbJFDSvW xSWrLuvkL0DXx7PF5NQyH0/Qig36ksmwddAD951dDHZM+Fibsvo2ir3sTf+OQwfqvl qe0pDZ/kFTafgW9GVhTCCCGu250H2s4qlRWChfbkKm5poGCZnUEjJqyRdNBpkLbgJd UWYj/W54a7d5nSuBriwYb5C+6AfloNEedguQi8HabFwZQvcr9FfrTygl1reabmtiYR StAJrr/C1JotwkyzLBEG4Z0RpB/kAKpqP/e5ciR9qB+ZYzezMR4tUF27nUdIM4DGIy h9EF9/XBgOldA== From: Heinrich Schuchardt To: Simon Glass Cc: Andrew Scull , =?utf-8?q?Pali_Roh=C3=A1r?= , Rasmus Villemoes , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/1] sandbox: fix return type of os_filesize() Date: Wed, 5 Apr 2023 10:59:41 +0200 Message-Id: <20230405085941.39110-1-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.39.2 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.8 at phobos.denx.de X-Virus-Status: Clean Given a file ../img of size 4294967296 with GPT partition table and partitions: => host bind 0 ../img => part list host 0 Disk host-0.blk not ready The cause is os_filesize() returning int. 4294967296 converted to int32_t gives 0. File sizes must use off_t. Correct all uses of os_filesize() too. Signed-off-by: Heinrich Schuchardt --- arch/sandbox/cpu/os.c | 8 ++++++-- drivers/block/host_dev.c | 3 ++- include/os.h | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 5e66304e2b..f8ad208e46 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -166,7 +166,7 @@ int os_write_file(const char *fname, const void *buf, int size) return 0; } -int os_filesize(int fd) +off_t os_filesize(int fd) { off_t size; @@ -218,7 +218,7 @@ err: int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep) { void *ptr; - int size; + off_t size; int ifd; ifd = os_open(pathname, os_flags); @@ -231,6 +231,10 @@ int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep) printf("Cannot get file size of '%s'\n", pathname); return -EIO; } + if (size > SIZE_MAX) { + printf("File '%s' too large to map\n", pathname); + return -EIO; + } ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { diff --git a/drivers/block/host_dev.c b/drivers/block/host_dev.c index 5885fc358a..64422417b7 100644 --- a/drivers/block/host_dev.c +++ b/drivers/block/host_dev.c @@ -24,7 +24,8 @@ static int host_sb_attach_file(struct udevice *dev, const char *filename) struct host_sb_plat *plat = dev_get_plat(dev); struct blk_desc *desc; struct udevice *blk; - int ret, fd, size; + int ret, fd; + off_t size; char *fname; if (!filename) diff --git a/include/os.h b/include/os.h index 0415f0f0e7..968412b0a8 100644 --- a/include/os.h +++ b/include/os.h @@ -64,7 +64,7 @@ off_t os_lseek(int fd, off_t offset, int whence); * @fd: File descriptor as returned by os_open() * Return: file size or negative error code */ -int os_filesize(int fd); +off_t os_filesize(int fd); /** * Access to the OS open() system call