From f4a9a3acc474f1f5379d397c9d197a1da47826a8 Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Sun, 27 Mar 2011 19:19:31 -0500 Subject: [PATCH] actually use strtol as intended, checking for invalid inputs --- src/NetworkSyncManager.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/NetworkSyncManager.cpp b/src/NetworkSyncManager.cpp index b58e5a46ff..303578235f 100644 --- a/src/NetworkSyncManager.cpp +++ b/src/NetworkSyncManager.cpp @@ -112,9 +112,16 @@ void NetworkSyncManager::PostStartUp( const RString& ServerIP ) size_t cLoc = ServerIP.find( ':' ); if( ServerIP.find( ':' ) != RString::npos ) { - char* cEnd; - iPort = (unsigned short)strtol( ServerIP.substr( cLoc + 1 ).c_str(), &cEnd, 10 ); sAddress = ServerIP.substr( 0, cLoc ); + char* cEnd; + errno = 0; + iPort = (unsigned short)strtol( ServerIP.substr( cLoc + 1 ).c_str(), &cEnd, 10 ); + if( *cEnd != 0 || errno != 0 ) + { + m_startupStatus = 2; + LOG->Warn( "Invalid port" ); + return; + } } else { @@ -137,7 +144,7 @@ void NetworkSyncManager::PostStartUp( const RString& ServerIP ) useSMserver = true; - m_startupStatus = 1; //Connection attepmpt successful + m_startupStatus = 1; // Connection attepmpt successful // If network play is desired and the connection works, // halt until we know what server version we're dealing with