From 0883a68a8114a28514fb05a6bf24e8c661e79e02 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 18 Jul 2024 22:32:35 -0700 Subject: [PATCH] vboxwrapper, Win: error out if getenv("USERPROFILE") fails --- samples/vboxwrapper/vbox_vboxmanage.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/samples/vboxwrapper/vbox_vboxmanage.cpp b/samples/vboxwrapper/vbox_vboxmanage.cpp index 4bfcf913d6..c17ebd87ad 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.cpp +++ b/samples/vboxwrapper/vbox_vboxmanage.cpp @@ -109,15 +109,20 @@ int VBOX_VM::initialize() { } else { // If the override environment variable isn't specified then // it is based of the current users HOME directory. + const char *home; #ifdef _WIN32 - virtualbox_home_directory = getenv("USERPROFILE"); + home = getenv("USERPROFILE"); + if (home == NULL) { + vboxlog_msg("no USERPROFILE - exiting"); + exit(1); + } #else - const char *home = getenv("HOME"); + home = getenv("HOME"); if (home == NULL) { home = getpwuid(getuid())->pw_dir; } - virtualbox_home_directory = home; #endif + virtualbox_home_directory = home; virtualbox_home_directory += "/.VirtualBox"; }