Skip to content
This repository was archived by the owner on Dec 4, 2021. It is now read-only.

Commit b396180

Browse files
author
Chris Board
committed
Fixed issue with possible overflow for SSH port and MySQL Port
Resolves issue where if a large number was used for the SSH port or remote MySQL port numberm it would cause an overflow and would therefore crash. Also improved the error handling so that errors processing the json are caught.
1 parent bc4e807 commit b396180

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

MySQLManager-TunnelPlugin_C++/TunnelManager.cpp

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -383,42 +383,52 @@ bool TunnelManager::processTunnelClosure(Document& jsonObject)
383383
*/
384384
bool TunnelManager::processTunnelCreation(Document& jsonObject)
385385
{
386-
//Determine the auth method
387-
const Value& sshDetails = jsonObject["sshDetails"];
388-
if (std::string(sshDetails["authMethod"].GetString()).compare("Password") == 0)
389-
{
390-
authMethod = AuthMethod::Password;
391-
}
392-
else
393-
{
394-
authMethod = AuthMethod::PrivateKey;
395-
}
396-
sshUsername = sshDetails["sshUsername"].GetString();
397-
if (authMethod == AuthMethod::Password)
398-
{
399-
sshPassword = sshDetails["sshPassword"].GetString();
400-
}
401-
else
386+
try
402387
{
403-
privateKey = sshDetails["privateSSHKey"].GetString();
404-
if (sshDetails.HasMember("certPassphrase"))
388+
//Determine the auth method
389+
const Value& sshDetails = jsonObject["sshDetails"];
390+
if (std::string(sshDetails["authMethod"].GetString()).compare("Password") == 0)
391+
{
392+
authMethod = AuthMethod::Password;
393+
}
394+
else
405395
{
406-
if (!sshDetails["certPassphrase"].IsNull())
396+
authMethod = AuthMethod::PrivateKey;
397+
}
398+
sshUsername = sshDetails["sshUsername"].GetString();
399+
if (authMethod == AuthMethod::Password)
400+
{
401+
sshPassword = sshDetails["sshPassword"].GetString();
402+
}
403+
else
404+
{
405+
privateKey = sshDetails["privateSSHKey"].GetString();
406+
if (sshDetails.HasMember("certPassphrase"))
407407
{
408-
certPassphrase = sshDetails["certPassphrase"].GetString();
408+
if (!sshDetails["certPassphrase"].IsNull())
409+
{
410+
certPassphrase = sshDetails["certPassphrase"].GetString();
411+
}
409412
}
410413
}
414+
sshPort = (unsigned long long)sshDetails["sshPort"].GetDouble();
415+
sshHost = sshDetails["sshHost"].GetString();
416+
remoteMySQLPort = (unsigned long long)jsonObject["remoteMySQLPort"].GetDouble();
417+
mysqlServerHost = jsonObject["mysqlHost"].GetString();
418+
fingerprintConfirmed = jsonObject["fingerprintConfirmed"].GetBool();
419+
if (jsonObject.HasMember("fingerprint"))
420+
{
421+
postedFingerprint = jsonObject["fingerprint"].GetString();
422+
}
423+
return true;
411424
}
412-
sshPort = sshDetails["sshPort"].GetInt();
413-
sshHost = sshDetails["sshHost"].GetString();
414-
remoteMySQLPort = jsonObject["remoteMySQLPort"].GetInt();
415-
mysqlServerHost = jsonObject["mysqlHost"].GetString();
416-
fingerprintConfirmed = jsonObject["fingerprintConfirmed"].GetBool();
417-
if (jsonObject.HasMember("fingerprint"))
425+
catch (exception& ex)
418426
{
419-
postedFingerprint = jsonObject["fingerprint"].GetString();
427+
stringstream logstream;
428+
logstream << "Failed to project JSON tunnel creation. Error: " << ex.what();
429+
this->logger->writeToLog(logstream.str(), "TunnelManager", "processTunnelCreation");
430+
return false;
420431
}
421-
return true;
422432
}
423433

424434
/**

MySQLManager-TunnelPlugin_C++/TunnelManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class TunnelManager
4646
std::string sshPassword;
4747
std::string privateKey;
4848
std::string certPassphrase;
49-
int sshPort;
49+
unsigned long long sshPort;
5050
std::string sshHost;
51-
int remoteMySQLPort;
51+
unsigned long long remoteMySQLPort;
5252
std::string mysqlServerHost;
5353
int localPort;
5454
static std::vector<ActiveTunnels> activeTunnelsList;

0 commit comments

Comments
 (0)