Skip to content

Commit

Permalink
Handle failure getting VNC directories
Browse files Browse the repository at this point in the history
Although rare, there are cases where we might fail to determine our base
directories. Make sure the code can handle it.
  • Loading branch information
CendioOssman committed Aug 29, 2024
1 parent 0c61c06 commit edee4db
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions vncviewer/vncviewer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -540,28 +540,47 @@ migrateDeprecatedOptions()
static void
create_base_dirs()
{
char *confdir = strdup(os::getvncconfigdir());
const char *dir;

dir = os::getvncconfigdir();
if (dir == nullptr) {
vlog.error(_("Could not determine VNC config directory path"));
return;
}

#ifndef WIN32
char *dotdir = strrchr(confdir, '.');
const char *dotdir = strrchr(dir, '.');
if (dotdir != nullptr && strcmp(dotdir, ".vnc") == 0)
vlog.info(_("~/.vnc is deprecated, please consult 'man vncviewer' for paths to migrate to."));
#else
char *vncdir = strrchr(confdir, '\\');
const char *vncdir = strrchr(dir, '\\');
if (vncdir != nullptr && strcmp(vncdir, "vnc") == 0)
vlog.info(_("%%APPDATA%%\\vnc is deprecated, please switch to the %%APPDATA%%\\TigerVNC location."));
#endif

if (os::mkdir_p(os::getvncconfigdir(), 0755) == -1) {
if (os::mkdir_p(dir, 0755) == -1) {
if (errno != EEXIST)
vlog.error(_("Could not create VNC config directory: %s"), strerror(errno));
}

if (os::mkdir_p(os::getvncdatadir(), 0755) == -1) {
dir = os::getvncdatadir();
if (dir == nullptr) {
vlog.error(_("Could not determine VNC data directory path"));
return;
}

if (os::mkdir_p(dir, 0755) == -1) {
if (errno != EEXIST)
vlog.error(_("Could not create VNC data directory: %s"), strerror(errno));
}

if (os::mkdir_p(os::getvncstatedir(), 0755) == -1) {
dir = os::getvncstatedir();
if (dir == nullptr) {
vlog.error(_("Could not determine VNC state directory path"));
return;
}

if (os::mkdir_p(dir, 0755) == -1) {
if (errno != EEXIST)
vlog.error(_("Could not create VNC state directory: %s"), strerror(errno));
}
Expand Down

0 comments on commit edee4db

Please sign in to comment.