The branch stable/13 has been updated by corvink:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=38b37099bb198128b309c08cf4583efd21e72f72

commit 38b37099bb198128b309c08cf4583efd21e72f72
Author:     Vitaliy Gusev <[email protected]>
AuthorDate: 2023-03-06 11:27:10 +0000
Commit:     Corvin Köhne <[email protected]>
CommitDate: 2023-03-17 10:26:33 +0000

    bhyvectl: do not return garbage from send_message
    
    err is used uninitialized in some cases.
    
    Reviewed by:            corvink, markj
    MFC after:              1 week
    Sponsored by:           vStack
    Differential Revision:  https://reviews.freebsd.org/D38886
    
    (cherry picked from commit 89fe7b98fe45cf56d60d0d4dfa1bfad3ba6908ec)
---
 usr.sbin/bhyvectl/bhyvectl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/bhyvectl/bhyvectl.c b/usr.sbin/bhyvectl/bhyvectl.c
index cab1e6d72c56..5efccc085119 100644
--- a/usr.sbin/bhyvectl/bhyvectl.c
+++ b/usr.sbin/bhyvectl/bhyvectl.c
@@ -1679,12 +1679,12 @@ static int
 send_message(const char *vmname, nvlist_t *nvl)
 {
        struct sockaddr_un addr;
-       int err, socket_fd;
+       int err = 0, socket_fd;
 
        socket_fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if (socket_fd < 0) {
                perror("Error creating bhyvectl socket");
-               err = -1;
+               err = errno;
                goto done;
        }
 
@@ -1700,8 +1700,10 @@ send_message(const char *vmname, nvlist_t *nvl)
                goto done;
        }
 
-       if (nvlist_send(socket_fd, nvl) < 0)
+       if (nvlist_send(socket_fd, nvl) < 0) {
                perror("nvlist_send() failed");
+               err = errno;
+       }
        nvlist_destroy(nvl);
 
 done:

Reply via email to