Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q2VkU-00037r-KL for mharc-grub-devel@gnu.org; Fri, 26 May 2023 07:36:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2VkT-00036y-2P for grub-devel@gnu.org; Fri, 26 May 2023 07:36:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2VkR-0005M7-Je for grub-devel@gnu.org; Fri, 26 May 2023 07:36:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685101002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F5FB1810KzhgdbS5l3Q+XGOWILrAKEY1CgeQLRZV2D4=; b=hJzmvfZ7Jom/rTjyBfviDU73Fz+RYETxemDim28UJc5cp2E0T6sQ0gtPL3Cnc533I1JiWL iby0VzDpVZ8ElmLG+7i4p02085xBbIATtwoQWvtBsfvbYs9hEotHuFE3e/LgVD3wq9S1pK 1BGzZCyFxhDrRaGFdS52mJPWdc233L4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-13-aoovHsDkP_yZX8Np9Gnw9g-1; Fri, 26 May 2023 07:36:36 -0400 X-MC-Unique: aoovHsDkP_yZX8Np9Gnw9g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AC02185A78B; Fri, 26 May 2023 11:36:36 +0000 (UTC) Received: from osteffen-laptop.redhat.com (unknown [10.39.193.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE6DC40CFD45; Fri, 26 May 2023 11:36:35 +0000 (UTC) From: Oliver Steffen To: grub-devel@gnu.org Cc: Daniel Kiper , Gerd Hoffmann , Oliver Steffen Subject: [PATCH v9 09/11] kern: check for NULL when closing devices and disks Date: Fri, 26 May 2023 13:35:50 +0200 Message-Id: <20230526113552.555635-10-osteffen@redhat.com> In-Reply-To: <20230526113552.555635-1-osteffen@redhat.com> References: <20230526113552.555635-1-osteffen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Received-SPF: pass client-ip=170.10.129.124; envelope-from=osteffen@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 May 2023 11:36:45 -0000 Add checks for NULL pointers to grub_device_close() and grub_disk_close() to make these functions more robust. Signed-off-by: Oliver Steffen --- grub-core/kern/device.c | 3 +++ grub-core/kern/disk.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c index 92ce8a75e..670e213cf 100644 --- a/grub-core/kern/device.c +++ b/grub-core/kern/device.c @@ -71,6 +71,9 @@ grub_device_open (const char *name) grub_err_t grub_device_close (grub_device_t device) { + if (device == NULL) + return GRUB_ERR_NONE; + if (device->disk) grub_disk_close (device->disk); diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index eb0c7bb73..1eda58fe9 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -292,6 +292,10 @@ void grub_disk_close (grub_disk_t disk) { grub_partition_t part; + + if (disk == NULL) + return; + grub_dprintf ("disk", "Closing `%s'.\n", disk->name); if (disk->dev && disk->dev->disk_close) -- 2.40.1