aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2024-08-29 17:19:40 +0200
committerLinn Mattsson <linma@cendio.se>2024-10-22 12:41:33 +0200
commitcf85f2365eaedc6828071d99105acd5307c65c02 (patch)
tree99c424882c94b926205aa533cd9478685bef871e
parentc5fc94af7b07bfad0263f407b85906dc38c8ef5b (diff)
downloadtigervnc-cf85f2365eaedc6828071d99105acd5307c65c02.tar.gz
tigervnc-cf85f2365eaedc6828071d99105acd5307c65c02.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. (cherry picked from commit edee4db8d1fd85495f189293041311bfff56d23c)
-rw-r--r--vncviewer/vncviewer.cxx31
1 files changed, 25 insertions, 6 deletions
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index d9f85f5a..8a60c42b 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -531,28 +531,47 @@ migrateDeprecatedOptions()
static void
create_base_dirs()
{
- char *confdir = strdup(os::getvncconfigdir());
+ const char *dir;
+
+ dir = os::getvncconfigdir();
+ if (dir == NULL) {
+ vlog.error(_("Could not determine VNC config directory path"));
+ return;
+ }
+
#ifndef WIN32
- char *dotdir = strrchr(confdir, '.');
+ const char *dotdir = strrchr(dir, '.');
if (dotdir != NULL && 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 != NULL && 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 == NULL) {
+ 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 == NULL) {
+ 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));
}