From: Pierre Ossman Date: Tue, 17 Jan 2023 18:09:26 +0000 (+0100) Subject: Remove trailing slash from getvnchomedir() X-Git-Tag: v1.13.90~87^2~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ef8c84eb752e1b59ef824cedeb156b2d64fefe37;p=tigervnc.git Remove trailing slash from getvnchomedir() It should return a path to the directory itself, just like its sister function getuserhomedir(). --- diff --git a/common/os/os.cxx b/common/os/os.cxx index 5492c55e..2dfabc46 100644 --- a/common/os/os.cxx +++ b/common/os/os.cxx @@ -66,7 +66,7 @@ static const char* gethomedir(bool userDir) if (userDir) return homedir; - snprintf(dir, sizeof(dir), "%s/.vnc/", homedir); + snprintf(dir, sizeof(dir), "%s/.vnc", homedir); return dir; #else @@ -81,10 +81,10 @@ static const char* gethomedir(bool userDir) if (userDir) return dir; - if (strlen(dir) + strlen("\\vnc\\") >= sizeof(dir)) + if (strlen(dir) + strlen("\\vnc") >= sizeof(dir)) return NULL; - strcat(dir, "\\vnc\\"); + strcat(dir, "\\vnc"); return dir; #endif diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index a8ef779d..c702280d 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -82,7 +82,7 @@ static const char* homedirfn(const char* fn) if (homedir == NULL) return ""; - snprintf(full_path, sizeof(full_path), "%s%s", homedir, fn); + snprintf(full_path, sizeof(full_path), "%s/%s", homedir, fn); return full_path; } @@ -395,8 +395,8 @@ void CSecurityTLS::checkSession() "path for known hosts storage"); } - CharArray dbPath(strlen(homeDir) + 16 + 1); - sprintf(dbPath.buf, "%sx509_known_hosts", homeDir); + CharArray dbPath(strlen(homeDir) + strlen("/x509_known_hosts") + 1); + sprintf(dbPath.buf, "%s/x509_known_hosts", homeDir); err = gnutls_verify_stored_pubkey(dbPath.buf, NULL, client->getServerName(), NULL, diff --git a/unix/vncpasswd/vncpasswd.cxx b/unix/vncpasswd/vncpasswd.cxx index 66c82144..4d91fda7 100644 --- a/unix/vncpasswd/vncpasswd.cxx +++ b/unix/vncpasswd/vncpasswd.cxx @@ -152,8 +152,8 @@ int main(int argc, char** argv) exit(1); } mkdir(homeDir, 0777); - fname = new char[strlen(homeDir) + 7]; - sprintf(fname, "%spasswd", homeDir); + fname = new char[strlen(homeDir) + strlen("/passwd") + 1]; + sprintf(fname, "%s/passwd", homeDir); } while (true) { diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx index a6b0e80f..db39cd59 100644 --- a/vncviewer/ServerDialog.cxx +++ b/vncviewer/ServerDialog.cxx @@ -320,7 +320,7 @@ void ServerDialog::loadServerHistory() throw Exception(_("Could not obtain the home directory path")); char filepath[PATH_MAX]; - snprintf(filepath, sizeof(filepath), "%s%s", homeDir, SERVER_HISTORY); + snprintf(filepath, sizeof(filepath), "%s/%s", homeDir, SERVER_HISTORY); /* Read server history from file */ FILE* f = fopen(filepath, "r"); @@ -386,7 +386,7 @@ void ServerDialog::saveServerHistory() throw Exception(_("Could not obtain the home directory path")); char filepath[PATH_MAX]; - snprintf(filepath, sizeof(filepath), "%s%s", homeDir, SERVER_HISTORY); + snprintf(filepath, sizeof(filepath), "%s/%s", homeDir, SERVER_HISTORY); /* Write server history to file */ FILE* f = fopen(filepath, "w+"); diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index 03f2b145..ff5589d2 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -633,7 +633,7 @@ void saveViewerParameters(const char *filename, const char *servername) { if (homeDir == NULL) throw Exception(_("Could not obtain the home directory path")); - snprintf(filepath, sizeof(filepath), "%sdefault.tigervnc", homeDir); + snprintf(filepath, sizeof(filepath), "%s/default.tigervnc", homeDir); } else { snprintf(filepath, sizeof(filepath), "%s", filename); } @@ -737,7 +737,7 @@ char* loadViewerParameters(const char *filename) { if (homeDir == NULL) throw Exception(_("Could not obtain the home directory path")); - snprintf(filepath, sizeof(filepath), "%sdefault.tigervnc", homeDir); + snprintf(filepath, sizeof(filepath), "%s/default.tigervnc", homeDir); } else { snprintf(filepath, sizeof(filepath), "%s", filename); }