From patchwork Thu Nov 10 07:40:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1702018 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=eZKZw74d; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N7DKK5Lffz1yqS for ; Thu, 10 Nov 2022 18:40:53 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9BF43850F4; Thu, 10 Nov 2022 08:40:47 +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 (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="eZKZw74d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1C503850F4; Thu, 10 Nov 2022 08:40:45 +0100 (CET) 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=unavailable 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 78670850EA for ; Thu, 10 Nov 2022 08:40:41 +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 workstation5.fritz.box (ip-084-118-157-002.um23.pools.vodafone-ip.de [84.118.157.2]) (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 953CE422B0; Thu, 10 Nov 2022 07:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1668066038; bh=yjfPQXWtLfDyD4tyhDvO68mMI57bVQiNHsn6DFXCXF8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=eZKZw74doqNfZUMs298rEMBobNCDdq7bklnUIMzIOi1Uu6yXUG057iu8ESS4AhmH3 lfe/z72ADgAfBXiX62BMjPoIfkDBMmA4wEyxkeU24KGRn/+qV/JLAxCC4l0cOuXswF /p1p/EilJ1308tZIh75ovOzw16H9Ben/ZV/p0vv6KiPmkUpqL0k3ltI2Q5aXCq0fii KuFzQWU/G4tkZtolMXEBM2eRLsVTZcGfJvhoF+RAusytzMDloB2DQr1XrHhkkOlmMh yNhrUkIPu7n/3znwIcYhfkWyz1vQpT8kNgAkULb0qqVrT+t39f1O8CoDI/Pn6jOjgg KrJscVkHp5f0g== From: Heinrich Schuchardt To: Marek Vasut Cc: Simon Glass , Andrew Scull , Sean Anderson , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/1] sandbox: check lseek return value in handle_ufi_command Date: Thu, 10 Nov 2022 08:40:30 +0100 Message-Id: <20221110074030.636411-1-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.37.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.6 at phobos.denx.de X-Virus-Status: Clean Invoking lseek() may result in an error. Handle it. Addresses-Coverity-ID: 376212 ("Error handling issues (CHECKED_RETURN)") Signed-off-by: Heinrich Schuchardt Signed-off-by: Heinrich Schuchardt --- drivers/usb/emul/sandbox_flash.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c index 6e8cfe1650..01ccc4bc17 100644 --- a/drivers/usb/emul/sandbox_flash.c +++ b/drivers/usb/emul/sandbox_flash.c @@ -188,15 +188,19 @@ static int handle_ufi_command(struct sandbox_flash_priv *priv, const void *buff, struct scsi_emul_info *info = &priv->eminfo; const struct scsi_cmd *req = buff; int ret; + off_t offset; ret = sb_scsi_emul_command(info, req, len); if (!ret) { setup_response(priv); } else if ((ret == SCSI_EMUL_DO_READ || ret == SCSI_EMUL_DO_WRITE) && priv->fd != -1) { - os_lseek(priv->fd, info->seek_block * info->block_size, - OS_SEEK_SET); - setup_response(priv); + offset = os_lseek(priv->fd, info->seek_block * info->block_size, + OS_SEEK_SET); + if (offset == (off_t)-1) + setup_fail_response(priv); + else + setup_response(priv); } else { setup_fail_response(priv); }