From 3969516d0b945d0151982915768c76e1c6f21761 Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Thu, 24 Dec 2009 18:49:50 +0000 Subject: [PATCH] - add check for bounds of internal cheats; --- desmume/src/cheatSystem.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index 4e5725c66..b1c436dec 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -655,16 +655,22 @@ BOOL CHEATS::load() strcpy(tmp_cht.description, (buf + descr_pos + 1)); tmp_cht.num = strlen(tmp_code) / 16; + if ((tmp_cht.type == 0) && (tmp_cht.num > 1)) + { + INFO("Cheats: Too many values for internal cheat\n", line); + continue; + } for (int i = 0; i < tmp_cht.num; i++) { char tmp_buf[9] = {0}; - + strncpy(tmp_buf, (char*)(tmp_code + (i*16)), 8); sscanf_s(tmp_buf, "%x", &tmp_cht.code[i][0]); if (tmp_cht.type == 0) { tmp_cht.size = std::min(3, ((tmp_cht.code[i][0] & 0xF0000000) >> 28)); + tmp_cht.code[i][0] &= 0x00FFFFFF; } strncpy(tmp_buf, (char*)(tmp_code + (i*16) + 8), 8);