aboutsummaryrefslogtreecommitdiffstats
path: root/vncviewer
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2019-03-26 11:11:20 +0100
committerPierre Ossman <ossman@cendio.se>2019-03-26 11:11:20 +0100
commit7240f62ddc06643f982456c05c11d8afe5422069 (patch)
treeb4edd3f32545dd2950eed16baa806516709e16ae /vncviewer
parent78bdd1700c4e42b492286a2af25bea0825848f99 (diff)
downloadtigervnc-7240f62ddc06643f982456c05c11d8afe5422069.tar.gz
tigervnc-7240f62ddc06643f982456c05c11d8afe5422069.zip
Handle server name overflow properly
We need to make sure it is null terminated on truncation. We also need to avoid giving a too large size argument or modern gcc will complain.
Diffstat (limited to 'vncviewer')
-rw-r--r--vncviewer/vncviewer.cxx9
1 files changed, 6 insertions, 3 deletions
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index d7cbd6e3..4a8370b9 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -411,7 +411,8 @@ potentiallyLoadConfigurationFile(char *vncServerName)
newServerName = loadViewerParameters(vncServerName);
// This might be empty, but we still need to clear it so we
// don't try to connect to the filename
- strncpy(vncServerName, newServerName, VNCSERVERNAMELEN);
+ strncpy(vncServerName, newServerName, VNCSERVERNAMELEN-1);
+ vncServerName[VNCSERVERNAMELEN-1] = '\0';
} catch (rfb::Exception& e) {
vlog.error("%s", e.str());
if (alertOnFatalError)
@@ -541,8 +542,10 @@ int main(int argc, char** argv)
try {
const char* configServerName;
configServerName = loadViewerParameters(NULL);
- if (configServerName != NULL)
- strncpy(defaultServerName, configServerName, VNCSERVERNAMELEN);
+ if (configServerName != NULL) {
+ strncpy(defaultServerName, configServerName, VNCSERVERNAMELEN-1);
+ defaultServerName[VNCSERVERNAMELEN-1] = '\0';
+ }
} catch (rfb::Exception& e) {
vlog.error("%s", e.str());
if (alertOnFatalError)