git: 225443828ec6 - stable/13 - bhyve: Avoid passing a possible garbage pointer to free().

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 26 Jan 2023 20:27:18 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=225443828ec69c7013666bf98a785bbf8b1036c2

commit 225443828ec69c7013666bf98a785bbf8b1036c2
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-11-29 01:10:30 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-26 20:24:14 +0000

    bhyve: Avoid passing a possible garbage pointer to free().
    
    All of the error paths in pci_vtcon_sock_add free the sock pointer.
    However, sock is not initialized until part way through the function.
    An early error would pass stack garbage to free().
    
    Reviewed by:    corvink, markj
    Differential Revision:  https://reviews.freebsd.org/D37491
    
    (cherry picked from commit bc928800723b65daa9b005bec4ffd8ad8c781a09)
---
 usr.sbin/bhyve/pci_virtio_console.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr.sbin/bhyve/pci_virtio_console.c b/usr.sbin/bhyve/pci_virtio_console.c
index 44d0da720226..46005d155f49 100644
--- a/usr.sbin/bhyve/pci_virtio_console.c
+++ b/usr.sbin/bhyve/pci_virtio_console.c
@@ -273,7 +273,7 @@ static int
 pci_vtcon_sock_add(struct pci_vtcon_softc *sc, const char *port_name,
     const nvlist_t *nvl)
 {
-	struct pci_vtcon_sock *sock;
+	struct pci_vtcon_sock *sock = NULL;
 	struct sockaddr_un sun;
 	const char *name, *path;
 	char *cp, *pathcopy;