Check finance_payment for int overflows

This commit is contained in:
wolfreak99 2017-01-10 20:50:40 -05:00 committed by Michał Janiszewski
parent 2235390ce2
commit 3e621d75f6
2 changed files with 9 additions and 2 deletions

View File

@ -73,9 +73,16 @@ uint8 gCommandExpenditureType;
void finance_payment(money32 amount, rct_expenditure_type type)
{
money32 cur_money = DECRYPT_MONEY(gCashEncrypted);
money32 new_money = cur_money - amount;
money32 new_money;
//overflow check
if (amount < 0 && cur_money >= INT_MAX + amount)
new_money = INT_MAX;
else if (amount >= 0 && cur_money < INT_MIN + amount)
new_money = INT_MIN;
else
new_money = cur_money - amount;
gCashEncrypted = ENCRYPT_MONEY(new_money);
gExpenditureTable[type] -= amount;
if (dword_988E60[type] & 1)

View File

@ -54,7 +54,7 @@ extern "C" {
// This define specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "28"
#define NETWORK_STREAM_VERSION "29"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
#ifdef __cplusplus