Skip to content

Commit

Permalink
xrGame: Adapt sscanf_s for ISO C++ (dangerous)
Browse files Browse the repository at this point in the history
This removes the size checks on Windows too.
  • Loading branch information
Zegeri committed Sep 16, 2018
1 parent 2cbf6c0 commit b122b5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
20 changes: 9 additions & 11 deletions src/xrGame/account_manager_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ void CCC_CreateGameSpyAccount::Execute(LPCSTR args)
string256 tmp_email;
string256 tmp_password;

sscanf_s(args, "%s %s %s %s", tmp_nick, sizeof(tmp_nick), tmp_unick, sizeof(tmp_unick), tmp_email,
sizeof(tmp_email), tmp_password, sizeof(tmp_password));
sscanf(args, "%s %s %s %s", tmp_nick, tmp_unick, tmp_email,tmp_password);

VERIFY(MainMenu() && MainMenu()->GetGS());
CGameSpy_GP* tmp_gp = MainMenu()->GetGS()->GetGameSpyGP();
Expand Down Expand Up @@ -54,7 +53,7 @@ void CCC_GapySpyListProfiles::Execute(LPCSTR args)
string256 tmp_email;
string256 tmp_password;

sscanf_s(args, "%s %s", tmp_email, sizeof(tmp_email), tmp_password, sizeof(tmp_password));
sscanf(args, "%s %s", tmp_email, tmp_password);

VERIFY(MainMenu() && MainMenu()->GetGS());
CGameSpy_GP* tmp_gp = MainMenu()->GetGS()->GetGameSpyGP();
Expand All @@ -76,8 +75,7 @@ void CCC_GameSpyLogin::Execute(LPCSTR args)
string256 tmp_nick;
string256 tmp_password;

sscanf_s(
args, "%s %s %s", tmp_email, sizeof(tmp_email), tmp_nick, sizeof(tmp_nick), tmp_password, sizeof(tmp_password));
sscanf(args, "%s %s %s", tmp_email, tmp_nick, tmp_password);

VERIFY(MainMenu() && MainMenu()->GetGS());
CGameSpy_GP* tmp_gp = MainMenu()->GetGS()->GetGameSpyGP();
Expand All @@ -97,7 +95,7 @@ void CCC_GameSpyLogout::Execute(LPCSTR args)

static char const* print_time(time_t const& src_time, string64& dest_time)
{
tm* tmp_tm = _localtime64(&src_time);
tm* tmp_tm = localtime(&src_time);
xr_sprintf(dest_time, sizeof(dest_time), "%02d.%02d.%d_%02d:%02d:%02d", tmp_tm->tm_mday, tmp_tm->tm_mon + 1,
tmp_tm->tm_year + 1900, tmp_tm->tm_hour, tmp_tm->tm_min, tmp_tm->tm_sec);
return dest_time;
Expand Down Expand Up @@ -153,7 +151,7 @@ void CCC_GameSpySuggestUNicks::Execute(LPCSTR args)
{
VERIFY(MainMenu() && MainMenu()->GetGS());
string256 tmp_unick;
sscanf_s(args, "%s", tmp_unick, sizeof(tmp_unick));
sscanf(args, "%s", tmp_unick);
gamespy_gp::account_manager* tmp_amngr = MainMenu()->GetAccountMngr();
VERIFY(tmp_amngr);
tmp_amngr->suggest_unique_nicks(tmp_unick, gamespy_gp::suggest_nicks_cb());
Expand All @@ -163,7 +161,7 @@ void CCC_GameSpyRegisterUniqueNick::Execute(LPCSTR args)
{
VERIFY(MainMenu() && MainMenu()->GetGS());
gamespy_gp::login_manager::unique_nick_t tmp_unick;
sscanf_s(args, "%s", tmp_unick, sizeof(tmp_unick));
sscanf(args, "%s", tmp_unick);
gamespy_gp::login_manager* tmp_lmngr = MainMenu()->GetLoginMngr();
VERIFY(tmp_lmngr);
tmp_lmngr->set_unique_nick(tmp_unick, gamespy_gp::login_operation_cb());
Expand Down Expand Up @@ -195,7 +193,7 @@ void CCC_GameSpyProfile::Execute(LPCSTR args)
}

string256 tmp_command;
sscanf_s(args, "%s", tmp_command, sizeof(tmp_command));
sscanf(args, "%s", tmp_command);
if (!xr_strcmp(tmp_command, "load"))
{
/*tmp_prof_store->set_current_profile(
Expand All @@ -214,7 +212,7 @@ void CCC_GameSpyProfile::Execute(LPCSTR args)
char const* tmp_reward_id_str = args + xr_strlen(tmp_command);
int tmp_award_id = 0;

if (!sscanf_s(tmp_reward_id_str, "%u", &tmp_award_id))
if (!sscanf(tmp_reward_id_str, "%u", &tmp_award_id))
{
Msg("! Bad award id");
return;
Expand All @@ -229,7 +227,7 @@ void CCC_GameSpyProfile::Execute(LPCSTR args)
char const* tmp_scores_str = args + xr_strlen(tmp_command);
unsigned int score_id = 0;
int score_value = 0;
if (sscanf_s(tmp_scores_str, "%u %u", &score_id, &score_value) != 2)
if (sscanf(tmp_scores_str, "%u %u", &score_id, &score_value) != 2)
{
Msg("! Not enough parameters");
return;
Expand Down
25 changes: 12 additions & 13 deletions src/xrGame/console_commands_mp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class CCC_KickPlayerByID : public IConsole_Command
else
{
u32 tmp_client_id;
if (sscanf_s(args, "%u", &tmp_client_id) != 1)
if (sscanf(args, "%u", &tmp_client_id) != 1)
{
Msg("! ERROR: bad command parameters.");
Msg("Kick player. Format: \"sv_kick_id <player session id | \'%s\'>\". To receive list of players ids "
Expand Down Expand Up @@ -508,7 +508,7 @@ class CCC_MakeScreenshot : public IConsole_Command
else
{
u32 tmp_client_id;
if (sscanf_s(args_, "%u", &tmp_client_id) != 1)
if (sscanf(args_, "%u", &tmp_client_id) != 1)
{
Msg("! ERROR: bad command parameters.");
Msg("Make screenshot. Format: \"make_screenshot <player session id | \'%s\'> <ban_time_in_sec>\". To "
Expand Down Expand Up @@ -556,7 +556,7 @@ class CCC_MakeConfigDump : public IConsole_Command
else
{
u32 tmp_client_id;
if (sscanf_s(args_, "%u", &tmp_client_id) != 1)
if (sscanf(args_, "%u", &tmp_client_id) != 1)
{
Msg("! ERROR: bad command parameters.");
Msg("Make screenshot. Format: \"make_config_dump <player session id | \'%s\'> <ban_time_in_sec>\". To "
Expand Down Expand Up @@ -615,7 +615,7 @@ class DemoPlayControlArgParser
string32 param_name;
param_name[0] = 0;

sscanf_s(args_string, "%16s %32s", action_name, sizeof(action_name), param_name, sizeof(param_name));
sscanf(args_string, "%16s %32s", action_name, param_name);
m_action_param = param_name;

if (!xr_strcmp(action_name, "roundstart"))
Expand Down Expand Up @@ -908,7 +908,7 @@ class CCC_BanPlayerByCDKEY : public IConsole_Command
if (!strncmp(args_, LAST_PRINTED_PLAYER_STR, sizeof(LAST_PRINTED_PLAYER_STR) - 1))
{
client_id = last_printed_player;
if (sscanf_s(args_ + sizeof(LAST_PRINTED_PLAYER_STR), "%d", &ban_time) != 1)
if (sscanf(args_ + sizeof(LAST_PRINTED_PLAYER_STR), "%d", &ban_time) != 1)
{
Msg("! ERROR: bad command parameters.");
Msg("Ban player. Format: \"sv_banplayer <player session id | \'%s\'> <ban_time_in_sec>\". To receive "
Expand All @@ -921,7 +921,7 @@ class CCC_BanPlayerByCDKEY : public IConsole_Command
else
{
u32 tmp_client_id;
if (sscanf_s(args_, "%u %d", &tmp_client_id, &ban_time) != 2)
if (sscanf(args_, "%u %d", &tmp_client_id, &ban_time) != 2)
{
Msg("! ERROR: bad command parameters.");
Msg("Ban player. Format: \"sv_banplayer <player session id | \'%s\'> <ban_time_in_sec>\". To receive "
Expand Down Expand Up @@ -970,7 +970,7 @@ class CCC_BanPlayerByCDKEYDirectly : public IConsole_Command

char hex_digest[64];
s32 ban_time = 0;
if (sscanf_s(args_, "%s %i", &hex_digest, sizeof(hex_digest), &ban_time) != 2)
if (sscanf(args_, "%s %i", &hex_digest, &ban_time) != 2)
{
Msg("! ERROR: bad command parameters.");
Msg("Ban player. Format: \"sv_banplayer_by_digest <hex digest> <ban_time_in_sec>\". To get player hex "
Expand Down Expand Up @@ -1012,7 +1012,7 @@ class CCC_UnBanPlayerByIndex : public IConsole_Command
{
// size_t ????? u32 maybe?
size_t player_index = 0;
if (sscanf_s(args_, "%u", &player_index) != 1)
if (sscanf(args_, "%u", &player_index) != 1)
{
Msg("! ERROR: bad command parameters.");
Msg(" Unban player. Format: \"sv_unbanplayer <banned player index | \'%s\'>. To receive list of banned "
Expand Down Expand Up @@ -1226,7 +1226,7 @@ class CCC_ListPlayers : public IConsole_Command
exclude_raid_from_args(args, tmp_dest, sizeof(tmp_dest));
if (xr_strlen(tmp_dest))
{
sscanf_s(tmp_dest, "%s", filter_string, sizeof(filter_string));
sscanf(tmp_dest, "%s", filter_string);
tmp_functor.filter_string = filter_string;
}
}
Expand Down Expand Up @@ -1323,7 +1323,7 @@ class CCC_ListPlayers_Banned : public IConsole_Command
exclude_raid_from_args(args, tmp_dest, sizeof(tmp_dest));
if (xr_strlen(tmp_dest))
{
sscanf_s(tmp_dest, "%s", filter_dest, sizeof(filter_dest));
sscanf(tmp_dest, "%s", filter_dest);
}
tmp_sv_game->PrintBanList(filter_dest);
Level().Server->Print_Banned_Addreses();
Expand Down Expand Up @@ -1356,8 +1356,7 @@ class CCC_ChangeLevelGameType : public IConsole_Command
string256 GameType;
GameType[0] = 0;

sscanf_s(args, "%255s %255s %255s", LevelName, sizeof(LevelName), LevelVersion, sizeof(LevelVersion), GameType,
sizeof(GameType));
sscanf(args, "%255s %255s %255s", LevelName, LevelVersion, GameType);

EGameIDs GameTypeID = ParseStringToGameType(GameType);
if (GameTypeID == eGameIDNoGame)
Expand Down Expand Up @@ -1450,7 +1449,7 @@ class CCC_ChangeLevel : public CCC_ChangeLevelGameType
string256 LevelVersion;
LevelName[0] = 0;
LevelVersion[0] = 0;
sscanf_s(args, "%255s %255s", LevelName, sizeof(LevelName), LevelVersion, sizeof(LevelVersion));
sscanf(args, "%255s %255s", LevelName, LevelVersion);

string1024 argsNew;
xr_sprintf(argsNew, "%s %s %s", LevelName, LevelVersion, Level().Server->GetGameState()->type_name());
Expand Down
5 changes: 2 additions & 3 deletions src/xrGame/game_cl_capture_the_artefact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ void game_cl_CaptureTheArtefact::OnVoteStart(NET_Packet& P)
command[psize - 1] = 0;
player[psize - 1] = 0;

sscanf_s(command, "%s", cmd_name, psize);
sscanf(command, "%s", cmd_name);
u32 cmd_len = xr_strlen(cmd_name);
u32 tcmd_len = cmd_len;

Expand All @@ -1276,8 +1276,7 @@ void game_cl_CaptureTheArtefact::OnVoteStart(NET_Packet& P)
Msg("---Vote command: %s", cmd_name);
#endif

int args_count = sscanf_s(command + cmd_len, scans_format, args[0], psize + 1, args[1], psize + 1, args[2],
psize + 1, args[3], psize + 1, args[4], psize + 1);
int args_count = sscanf(command + cmd_len, scans_format, args[0], args[1], args[2], args[3], args[4]);
if (args_count < 0)
args_count = 0;

Expand Down

0 comments on commit b122b5b

Please sign in to comment.