5264: Prevent users from setting port 1-1023 r=Jupeyy a=def-

Following user report that they set cl_port 1 and it didn't work

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


5266: Use std::make_unique (fixes #5166) r=Jupeyy a=def-

No idea why clang-tidy's modernize-... didn't work

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2022-05-28 16:01:32 +00:00 committed by GitHub
commit 719e3e4385
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 20 deletions

View file

@ -3004,6 +3004,7 @@ foreach(target ${TARGETS_OWN})
if((CMAKE_VERSION VERSION_GREATER 3.1 OR CMAKE_VERSION VERSION_EQUAL 3.1))
set_property(TARGET ${target} PROPERTY CXX_STANDARD 17)
set_property(TARGET ${target} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${target} PROPERTY CXX_EXTENSIONS OFF)
endif()
if(MSVC)

View file

@ -162,7 +162,7 @@ public:
};
std::unique_ptr<ILogger> log_logger_android()
{
return std::unique_ptr<ILogger>(new CLoggerAndroid());
return std::make_unique<CLoggerAndroid>();
}
#else
std::unique_ptr<ILogger> log_logger_android()
@ -199,7 +199,7 @@ public:
std::unique_ptr<ILogger> log_logger_collection(std::vector<std::shared_ptr<ILogger>> &&loggers)
{
return std::unique_ptr<ILogger>(new CLoggerCollection(std::move(loggers)));
return std::make_unique<CLoggerCollection>(std::move(loggers));
}
class CLoggerAsync : public ILogger
@ -261,7 +261,7 @@ public:
std::unique_ptr<ILogger> log_logger_file(IOHANDLE logfile)
{
return std::unique_ptr<ILogger>(new CLoggerAsync(logfile, false, true));
return std::make_unique<CLoggerAsync>(logfile, false, true);
}
#if defined(CONF_FAMILY_WINDOWS)
@ -372,17 +372,17 @@ std::unique_ptr<ILogger> log_logger_stdout()
// TODO: Only enable true color when COLORTERM contains "truecolor".
// https://github.com/termstandard/colors/tree/65bf0cd1ece7c15fa33a17c17528b02c99f1ae0b#checking-for-colorterm
const bool colors = getenv("NO_COLOR") == nullptr && isatty(STDOUT_FILENO);
return std::unique_ptr<ILogger>(new CLoggerAsync(io_stdout(), colors, false));
return std::make_unique<CLoggerAsync>(io_stdout(), colors, false);
#else
if(GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == FILE_TYPE_UNKNOWN)
AttachConsole(ATTACH_PARENT_PROCESS);
HANDLE pOutput = GetStdHandle(STD_OUTPUT_HANDLE);
switch(GetFileType(pOutput))
{
case FILE_TYPE_CHAR: return std::unique_ptr<ILogger>(new CWindowsConsoleLogger(pOutput));
case FILE_TYPE_CHAR: return std::make_unique<CWindowsConsoleLogger>(pOutput);
case FILE_TYPE_PIPE: // fall through, writing to pipe works the same as writing to a file
case FILE_TYPE_DISK: return std::unique_ptr<ILogger>(new CWindowsFileLogger(pOutput));
default: return std::unique_ptr<ILogger>(new CLoggerAsync(io_stdout(), false, false));
case FILE_TYPE_DISK: return std::make_unique<CWindowsFileLogger>(pOutput);
default: return std::make_unique<CLoggerAsync>(io_stdout(), false, false);
}
#endif
}
@ -400,7 +400,7 @@ public:
};
std::unique_ptr<ILogger> log_logger_windows_debugger()
{
return std::unique_ptr<ILogger>(new CLoggerWindowsDebugger());
return std::make_unique<CLoggerWindowsDebugger>();
}
#else
std::unique_ptr<ILogger> log_logger_windows_debugger()

View file

@ -2987,7 +2987,12 @@ void CClient::Run()
}
for(unsigned int i = 0; i < std::size(m_NetClient); i++)
{
BindAddr.port = i == CONN_MAIN ? g_Config.m_ClPort : i == CONN_DUMMY ? g_Config.m_ClDummyPort : g_Config.m_ClContactPort;
int &PortRef = i == CONN_MAIN ? g_Config.m_ClPort : i == CONN_DUMMY ? g_Config.m_ClDummyPort : g_Config.m_ClContactPort;
if(PortRef < 1024) // Reject users setting ports that we don't want to use
{
PortRef = 0;
}
BindAddr.port = PortRef;
while(BindAddr.port == 0 || !m_NetClient[i].Open(BindAddr))
{
BindAddr.port = (secure_rand() % 64511) + 1024;

View file

@ -713,7 +713,7 @@ std::unique_ptr<IDbConnection> CreateMysqlConnection(
int Port,
bool Setup)
{
return std::unique_ptr<IDbConnection>(new CMysqlConnection(pDatabase, pPrefix, pUser, pPass, pIp, Port, Setup));
return std::make_unique<CMysqlConnection>(pDatabase, pPrefix, pUser, pPass, pIp, Port, Setup);
}
#else
int MysqlInit()

View file

@ -387,5 +387,5 @@ bool CSqliteConnection::AddPoints(const char *pPlayer, int Points, char *pError,
std::unique_ptr<IDbConnection> CreateSqliteConnection(const char *pFilename, bool Setup)
{
return std::unique_ptr<IDbConnection>(new CSqliteConnection(pFilename, Setup));
return std::make_unique<CSqliteConnection>(pFilename, Setup);
}

View file

@ -3906,7 +3906,7 @@ int main(int argc, const char **argv)
dbg_msg("client", "failed to open '%s' for logging", g_Config.m_Logfile);
}
}
pEngine->SetAdditionalLogger(std::unique_ptr<ILogger>(new CServerLogger(pServer)));
pEngine->SetAdditionalLogger(std::make_unique<CServerLogger>(pServer));
// run the server
dbg_msg("server", "starting...");

View file

@ -77,5 +77,5 @@ std::unique_ptr<ILogger> CreateAssertionLogger(IStorage *pStorage, const char *p
{
char aAssertLogPath[IO_MAX_PATH_LENGTH];
pStorage->GetCompletePath(IStorage::TYPE_SAVE, "dumps/", aAssertLogPath, sizeof(aAssertLogPath));
return std::unique_ptr<ILogger>(new CAssertionLogger(aAssertLogPath, pGameName));
return std::make_unique<CAssertionLogger>(aAssertLogPath, pGameName);
}

View file

@ -131,9 +131,9 @@ MACRO_CONFIG_INT(InpMouseOld, inp_mouseold, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIE
MACRO_CONFIG_INT(InpTranslatedKeys, inp_translated_keys, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Translate keys before interpreting them, respects keyboard layouts")
MACRO_CONFIG_INT(InpIgnoredModifiers, inp_ignored_modifiers, 0, 0, 65536, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Ignored keyboard modifier mask")
MACRO_CONFIG_INT(ClPort, cl_port, 0, 0, 65535, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Port to use for client connections to server (0 to choose a random port, requires a restart)")
MACRO_CONFIG_INT(ClDummyPort, cl_dummy_port, 0, 0, 65535, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Port to use for dummy connections to server (0 to choose a random port, requires a restart)")
MACRO_CONFIG_INT(ClContactPort, cl_contact_port, 0, 0, 65535, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Port to use for serverinfo connections to server (0 to choose a random port, requires a restart)")
MACRO_CONFIG_INT(ClPort, cl_port, 0, 0, 65535, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Port to use for client connections to server (0 to choose a random port, 1024 or higher to set a manual port, requires a restart)")
MACRO_CONFIG_INT(ClDummyPort, cl_dummy_port, 0, 0, 65535, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Port to use for dummy connections to server (0 to choose a random port, 1024 or higher to set a manual port, requires a restart)")
MACRO_CONFIG_INT(ClContactPort, cl_contact_port, 0, 0, 65535, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Port to use for serverinfo connections to server (0 to choose a random port, 1024 or higher to set a manual port, requires a restart)")
MACRO_CONFIG_STR(SvName, sv_name, 128, "unnamed server", CFGFLAG_SERVER, "Server name")
MACRO_CONFIG_STR(Bindaddr, bindaddr, 128, "", CFGFLAG_CLIENT | CFGFLAG_SERVER | CFGFLAG_MASTER, "Address to bind the client/server to")

View file

@ -154,14 +154,14 @@ public:
inline std::unique_ptr<CHttpRequest> HttpHead(const char *pUrl)
{
std::unique_ptr<CHttpRequest> pResult = std::unique_ptr<CHttpRequest>(new CHttpRequest(pUrl));
auto pResult = std::make_unique<CHttpRequest>(pUrl);
pResult->Head();
return pResult;
}
inline std::unique_ptr<CHttpRequest> HttpGet(const char *pUrl)
{
return std::unique_ptr<CHttpRequest>(new CHttpRequest(pUrl));
return std::make_unique<CHttpRequest>(pUrl);
}
inline std::unique_ptr<CHttpRequest> HttpGetFile(const char *pUrl, IStorage *pStorage, const char *pOutputFile, int StorageType)
@ -174,14 +174,14 @@ inline std::unique_ptr<CHttpRequest> HttpGetFile(const char *pUrl, IStorage *pSt
inline std::unique_ptr<CHttpRequest> HttpPost(const char *pUrl, const unsigned char *pData, size_t DataLength)
{
std::unique_ptr<CHttpRequest> pResult = std::unique_ptr<CHttpRequest>(new CHttpRequest(pUrl));
auto pResult = std::make_unique<CHttpRequest>(pUrl);
pResult->Post(pData, DataLength);
return pResult;
}
inline std::unique_ptr<CHttpRequest> HttpPostJson(const char *pUrl, const char *pJson)
{
std::unique_ptr<CHttpRequest> pResult = std::unique_ptr<CHttpRequest>(new CHttpRequest(pUrl));
auto pResult = std::make_unique<CHttpRequest>(pUrl);
pResult->PostJson(pJson);
return pResult;
}