diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-08-29 17:19:40 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-08-29 17:23:56 +0200 |
commit | edee4db8d1fd85495f189293041311bfff56d23c (patch) | |
tree | d7eab53cbb17274297e8344ebb16b8509f1fb5d4 /vncviewer/vncviewer.cxx | |
parent | 0c61c069bab38d14b93ad9d71b6509427a5611a8 (diff) | |
download | tigervnc-edee4db8d1fd85495f189293041311bfff56d23c.tar.gz tigervnc-edee4db8d1fd85495f189293041311bfff56d23c.zip |
Handle failure getting VNC directories
Although rare, there are cases where we might fail to determine our base
directories. Make sure the code can handle it.
Diffstat (limited to 'vncviewer/vncviewer.cxx')
-rw-r--r-- | vncviewer/vncviewer.cxx | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 0aec1910..c206427b 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -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)); } |