Fixed the ancient buffer overflows in Memory Watch.

This commit is contained in:
aquanull@gmail.com 2018-12-24 12:01:25 +08:00
parent 3b531d0d7c
commit fe64ca3771
2 changed files with 54 additions and 51 deletions

View File

@ -2242,7 +2242,7 @@ BOOL CALLBACK MemFindCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
break; break;
case WM_CLOSE: case WM_CLOSE:
case WM_QUIT: case WM_QUIT:
GetDlgItemText(hwndDlg,IDC_MEMVIEWFIND_WHAT,FindTextBox,59); GetDlgItemText(hwndDlg,IDC_MEMVIEWFIND_WHAT,FindTextBox,60);
DestroyWindow(hwndDlg); DestroyWindow(hwndDlg);
hMemFind = 0; hMemFind = 0;
hwndDlg = 0; hwndDlg = 0;
@ -2302,7 +2302,7 @@ void FindNext(){
unsigned char data[60]; unsigned char data[60];
int datasize = 0, i, j, inputc = -1, found; int datasize = 0, i, j, inputc = -1, found;
if(hMemFind) GetDlgItemText(hMemFind,IDC_MEMVIEWFIND_WHAT,str,59); if(hMemFind) GetDlgItemText(hMemFind,IDC_MEMVIEWFIND_WHAT,str,60);
else strcpy(str,FindTextBox); else strcpy(str,FindTextBox);
for(i = 0;str[i] != 0;i++){ for(i = 0;str[i] != 0;i++){

View File

@ -72,12 +72,12 @@ extern void RemoveRecentItem(unsigned int which, char**bufferArray, const unsign
//Ram change monitor globals----------------------------------- //Ram change monitor globals-----------------------------------
bool RamChangeInitialize = false; //Set true during memw WM_INIT bool RamChangeInitialize = false; //Set true during memw WM_INIT
const int MAX_RAMMONITOR = 4; //Maximum number of Ram values that can be monitored const int MAX_RAMMONITOR = 4; //Maximum number of Ram values that can be monitored
char editboxnow[MAX_RAMMONITOR][5]; //current address put into editbox 00 char editboxnow[MAX_RAMMONITOR][8]; //current address put into editbox 00
char editboxlast[MAX_RAMMONITOR][5]; //last address put into editbox (1 frame ago) char editboxlast[MAX_RAMMONITOR][8]; //last address put into editbox (1 frame ago)
int editlast[MAX_RAMMONITOR]; //last address value (1 frame ago) int editlast[MAX_RAMMONITOR]; //last address value (1 frame ago)
int editnow[MAX_RAMMONITOR]; //current address value int editnow[MAX_RAMMONITOR]; //current address value
unsigned int editcount[MAX_RAMMONITOR]; //Current counter value unsigned int editcount[MAX_RAMMONITOR]; //Current counter value
char editchangem[MAX_RAMMONITOR][5]; //counter converted to string char editchangem[MAX_RAMMONITOR][12]; //counter converted to string
//------------------------------------------------- //-------------------------------------------------
@ -336,7 +336,6 @@ void UpdateMemWatch()
TextOut(hdc,0,0,text,strlen(text)); TextOut(hdc,0,0,text,strlen(text));
SetTextColor(hdc,RGB(0,0,0)); SetTextColor(hdc,RGB(0,0,0));
} }
} }
} }
@ -388,14 +387,14 @@ bool iftextchanged()
int i,j; int i,j;
for(i=0;i<NUMWATCHES;i++) for(i=0;i<NUMWATCHES;i++)
{ {
for(j=0;j<LABELLENGTH;j++) for(j=0;j<ADDRESSLENGTH;j++)
{ {
if(addresses[i][j] != NULL || labels [i][j] != NULL) if(addresses[i][j] != '\0' || labels [i][j] != '\0')
return true; return true;
} }
for(;j<LABELLENGTH;j++) for(;j<LABELLENGTH;j++)
{ {
if(labels[i][j] != NULL) if(labels[i][j] != '\0')
return true; return true;
} }
} }
@ -445,16 +444,16 @@ static void SaveMemWatch()
for(i=0;i<NUMWATCHES;i++) for(i=0;i<NUMWATCHES;i++)
{ {
//Use dummy strings to fill empty slots //Use dummy strings to fill empty slots
if(labels[i][0] == 0)
{
labels[i][0] = '|';
labels[i][1] = 0;
}
if(addresses[i][0] == 0) if(addresses[i][0] == 0)
{ {
addresses[i][0] = '|'; addresses[i][0] = '|';
addresses[i][1] = 0; addresses[i][1] = 0;
} }
if(labels[i][0] == 0)
{
labels[i][0] = '|';
labels[i][1] = 0;
}
//spaces can be a problem for scanf so get rid of them //spaces can be a problem for scanf so get rid of them
TakeOutSpaces(i); TakeOutSpaces(i);
fprintf(fp, "%s %s\n", addresses[i], labels[i]); fprintf(fp, "%s %s\n", addresses[i], labels[i]);
@ -476,16 +475,16 @@ static void QuickSaveMemWatch() //Save rather than Save as
for(int i=0;i<NUMWATCHES;i++) for(int i=0;i<NUMWATCHES;i++)
{ {
//Use dummy strings to fill empty slots //Use dummy strings to fill empty slots
if(labels[i][0] == 0)
{
labels[i][0] = '|';
labels[i][1] = 0;
}
if(addresses[i][0] == 0) if(addresses[i][0] == 0)
{ {
addresses[i][0] = '|'; addresses[i][0] = '|';
addresses[i][1] = 0; addresses[i][1] = 0;
} }
if(labels[i][0] == 0)
{
labels[i][0] = '|';
labels[i][1] = 0;
}
//spaces can be a problem for scanf so get rid of them //spaces can be a problem for scanf so get rid of them
TakeOutSpaces(i); TakeOutSpaces(i);
fprintf(fp, "%s %s\n", addresses[i], labels[i]); fprintf(fp, "%s %s\n", addresses[i], labels[i]);
@ -958,11 +957,15 @@ void CreateMemWatch()
int i,j; int i,j;
for(i=0;i<NUMWATCHES;i++) for(i=0;i<NUMWATCHES;i++)
{ {
for(j=0;j<LABELLENGTH;j++) for(j=0;j<ADDRESSLENGTH;j++)
{ {
addresses[i][j] = 0; addresses[i][j] = 0;
labels[i][j] = 0; labels[i][j] = 0;
} }
for (;j<LABELLENGTH;j++)
{
labels[i][j] = 0;
}
} }
} }