git: 6d162b90b54b - stable/13 - stand: Unbreak FAT32 in loader

From: Michael Gmelin <grembo_at_FreeBSD.org>
Date: Wed, 05 Oct 2022 11:48:37 UTC
The branch stable/13 has been updated by grembo (ports committer):

URL: https://cgit.FreeBSD.org/src/commit/?id=6d162b90b54b6733bdb91b82f3b97ac84c6b9f8c

commit 6d162b90b54b6733bdb91b82f3b97ac84c6b9f8c
Author:     Michael Gmelin <grembo@FreeBSD.org>
AuthorDate: 2022-09-07 16:56:49 +0000
Commit:     Michael Gmelin <grembo@FreeBSD.org>
CommitDate: 2022-10-05 11:47:39 +0000

    stand: Unbreak FAT32 in loader
    
    This corrects an issue introduced in b4cb3fe0e39a3, where a freshly
    allocated `DOS_FS` structure would not be initialized properly before
    use in `dos_open`.
    
    In case of FAT32 file systems, this would leave `fs->dirents`
    uninitialized and - depending on its content and due to checks in
    `parsebs` - prevent mounting the file system successfully.
    
    This particularily impacted the EFI loader, as it was sometimes not
    able to read files from a FAT32-formatted EFI partition, including
    LoaderEnv (`/efi/freebsd/loader.env`).
    
    Accepted by:    imp
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D36482
    
    (cherry picked from commit 0eb736c0f673d2804a0c8c14fa1e4eae228ab6d2)
---
 stand/libsa/dosfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stand/libsa/dosfs.c b/stand/libsa/dosfs.c
index 452a79ae12dc..b931648a364b 100644
--- a/stand/libsa/dosfs.c
+++ b/stand/libsa/dosfs.c
@@ -322,7 +322,7 @@ dos_open(const char *path, struct open_file *fd)
 
 	if (mnt == NULL) {
 		/* Allocate mount structure, associate with open */
-		if ((fs = malloc(sizeof(DOS_FS))) == NULL)
+		if ((fs = calloc(1, sizeof(DOS_FS))) == NULL)
 			return (errno);
 		if ((err = dos_mount_impl(fs, fd))) {
 			free(fs);