Fix configfile buffer overrun (Mac mods missing fix)

This commit is contained in:
MysterD 2022-02-04 00:43:49 -08:00
parent 44b1d89c58
commit 73ecd55eb9
1 changed files with 5 additions and 4 deletions

View File

@ -34,6 +34,7 @@ struct ConfigOption {
float* floatValue;
char* stringValue;
};
int maxStringLength;
};
/*
@ -177,7 +178,7 @@ static const struct ConfigOption options[] = {
{.name = "discordrpc_enable", .type = CONFIG_TYPE_BOOL, .boolValue = &configDiscordRPC},
#endif
// coop-specific
{.name = "coop_join_ip", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configJoinIp},
{.name = "coop_join_ip", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configJoinIp, .maxStringLength = MAX_CONFIG_STRING},
{.name = "coop_join_port", .type = CONFIG_TYPE_UINT , .uintValue = &configJoinPort},
{.name = "coop_host_port", .type = CONFIG_TYPE_UINT , .uintValue = &configHostPort},
{.name = "coop_host_save_slot", .type = CONFIG_TYPE_UINT , .uintValue = &configHostSaveSlot},
@ -185,7 +186,7 @@ static const struct ConfigOption options[] = {
{.name = "coop_player_knockback_strength", .type = CONFIG_TYPE_UINT , .uintValue = &configPlayerKnockbackStrength},
{.name = "coop_stay_in_level_after_star", .type = CONFIG_TYPE_UINT , .boolValue = &configStayInLevelAfterStar},
{.name = "coop_network_system", .type = CONFIG_TYPE_UINT , .uintValue = &configNetworkSystem},
{.name = "coop_player_name", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configPlayerName},
{.name = "coop_player_name", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configPlayerName, .maxStringLength = MAX_PLAYER_STRING},
{.name = "coop_player_model", .type = CONFIG_TYPE_UINT , .uintValue = &configPlayerModel},
{.name = "coop_player_palette", .type = CONFIG_TYPE_UINT , .uintValue = &configPlayerPalette},
{.name = "coop_60fps", .type = CONFIG_TYPE_UINT , .uintValue = &config60Fps},
@ -344,8 +345,8 @@ void configfile_load(const char *filename) {
sscanf(tokens[1], "%f", option->floatValue);
break;
case CONFIG_TYPE_STRING:
memset(option->stringValue, '\0', MAX_CONFIG_STRING);
strncpy(option->stringValue, tokens[1], MAX_CONFIG_STRING);
memset(option->stringValue, '\0', option->maxStringLength);
snprintf(option->stringValue, option->maxStringLength, "%s", tokens[1]);
break;
default:
assert(0); // bad type