Debugger: add index bounds checks for zpa and wa cmds

. fix zpc
This commit is contained in:
tomcw 2023-01-05 20:40:38 +00:00
parent 71076b9cce
commit d01a9ccb40
2 changed files with 36 additions and 32 deletions

View File

@ -6734,28 +6734,27 @@ Update_t _ViewOutput( ViewVideoPage_t iPage, int bVideoModeFlags )
// Watches ________________________________________________________________________________________
//===========================================================================
Update_t CmdWatch (int nArgs)
{
return CmdWatchAdd( nArgs );
}
//===========================================================================
Update_t CmdWatchAdd (int nArgs)
{
// WA [address]
// WA # address
if (! nArgs)
if (!nArgs)
{
return CmdWatchList( 0 );
return CmdWatchList(0);
}
int iArg = 1;
int iWatch = NO_6502_TARGET;
if (nArgs > 1)
{
iWatch = g_aArgs[ 1 ].nValue;
iWatch = g_aArgs[1].nValue;
if (iWatch >= MAX_WATCHES)
{
ConsoleDisplayPushFormat("Watch index too big. (Max: %d)", MAX_WATCHES - 1);
return ConsoleUpdate();
}
iArg++;
}
@ -6778,7 +6777,7 @@ Update_t CmdWatchAdd (int nArgs)
// Make sure address isn't an IO address
if ((nAddress >= _6502_IO_BEGIN) && (nAddress <= _6502_IO_END))
return ConsoleDisplayError("You may not watch an I/O location.");
return ConsoleDisplayError("You cannot watch an I/O location.");
if (iWatch == NO_6502_TARGET)
{
@ -6791,7 +6790,7 @@ Update_t CmdWatchAdd (int nArgs)
if ((iWatch >= MAX_WATCHES) && !bAdded)
{
ConsoleDisplayPushFormat( "All watches are currently in use. (Max: %d)", MAX_WATCHES );
ConsoleDisplayPushFormat("All watches are currently in use. (Max: %d)", MAX_WATCHES);
return ConsoleUpdate();
}
@ -7270,21 +7269,13 @@ Update_t CmdWindowLast (int nArgs)
//===========================================================================
Update_t CmdZeroPage (int nArgs)
{
// ZP [address]
// ZP # address
return CmdZeroPageAdd( nArgs );
}
//===========================================================================
Update_t CmdZeroPageAdd (int nArgs)
Update_t CmdZeroPageAdd (int nArgs)
{
// ZP [address]
// ZP # address [address...]
if (! nArgs)
if (!nArgs)
{
return CmdZeroPageList( 0 );
return CmdZeroPageList(0);
}
int iArg = 1;
@ -7292,7 +7283,13 @@ Update_t CmdZeroPageAdd (int nArgs)
if (nArgs > 1)
{
iZP = g_aArgs[ 1 ].nValue;
iZP = g_aArgs[1].nValue;
if (iZP >= MAX_ZEROPAGE_POINTERS)
{
ConsoleDisplayPushFormat("Zero page pointer index too big. (Max: %d)", MAX_ZEROPAGE_POINTERS - 1);
return ConsoleUpdate();
}
iArg++;
}
@ -7301,6 +7298,13 @@ Update_t CmdZeroPageAdd (int nArgs)
{
WORD nAddress = g_aArgs[iArg].nValue;
// Make sure address is a ZP address
if (nAddress > _6502_ZEROPAGE_END)
{
ConsoleDisplayPushFormat("Zero page pointer must be in the range: [00..%02X].", _6502_ZEROPAGE_END);
return ConsoleUpdate();
}
if (iZP == NO_6502_TARGET)
{
iZP = 0;
@ -7312,7 +7316,7 @@ Update_t CmdZeroPageAdd (int nArgs)
if ((iZP >= MAX_ZEROPAGE_POINTERS) && !bAdded)
{
ConsoleDisplayPushFormat( "All zero page pointers are currently in use. (Max: %d)", MAX_ZEROPAGE_POINTERS );
ConsoleDisplayPushFormat("All zero page pointers are currently in use. (Max: %d)", MAX_ZEROPAGE_POINTERS);
return ConsoleUpdate();
}
@ -7345,9 +7349,9 @@ Update_t _ZeroPage_Error()
}
//===========================================================================
Update_t CmdZeroPageClear (int nArgs)
Update_t CmdZeroPageClear (int nArgs)
{
if (!g_nBreakpoints)
if (!g_nZeroPagePointers)
return _ZeroPage_Error();
// CHECK FOR ERRORS
@ -7356,7 +7360,7 @@ Update_t CmdZeroPageClear (int nArgs)
_BWZ_ClearViaArgs( nArgs, g_aZeroPagePointers, MAX_ZEROPAGE_POINTERS, g_nZeroPagePointers );
if (! g_nZeroPagePointers)
if (!g_nZeroPagePointers)
{
UpdateDisplay( UPDATE_BACKGROUND );
return UPDATE_CONSOLE_DISPLAY;
@ -7379,7 +7383,7 @@ Update_t CmdZeroPageDisable (int nArgs)
}
//===========================================================================
Update_t CmdZeroPageEnable (int nArgs)
Update_t CmdZeroPageEnable (int nArgs)
{
if (! g_nZeroPagePointers)
return _ZeroPage_Error();
@ -7393,7 +7397,7 @@ Update_t CmdZeroPageEnable (int nArgs)
}
//===========================================================================
Update_t CmdZeroPageList (int nArgs)
Update_t CmdZeroPageList (int nArgs)
{
if (! g_nZeroPagePointers)
{

View File

@ -274,7 +274,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
{TEXT("DHGR2") , CmdViewOutput_DHGR2 , CMD_VIEW_DHGR2 , "View Double Hi-res Page 2" },
{TEXT("SHR") , CmdViewOutput_SHR , CMD_VIEW_SHR , "View Super Hi-res" },
// Watch
{TEXT("W") , CmdWatch , CMD_WATCH , "Alias for WA (Watch Add)" },
{TEXT("W") , CmdWatchAdd , CMD_WATCH , "Alias for WA (Watch Add)" },
{TEXT("WA") , CmdWatchAdd , CMD_WATCH_ADD , "Add/Update address or symbol to watch" },
{TEXT("WC") , CmdWatchClear , CMD_WATCH_CLEAR , "Clear (remove) watch" },
{TEXT("WD") , CmdWatchDisable , CMD_WATCH_DISABLE , "Disable specific watch - it is still in the list, just not active" },
@ -300,7 +300,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// {TEXT("WINSOURCE") , CmdWindowShowSource , CMD_WINDOW_SOURCE },
// {TEXT("ZEROPAGE") , CmdWindowShowZeropage, CMD_WINDOW_ZEROPAGE },
// Zero Page
{TEXT("ZP") , CmdZeroPage , CMD_ZEROPAGE_POINTER , "Alias for ZPA (Zero Page Add)" },
{TEXT("ZP") , CmdZeroPageAdd , CMD_ZEROPAGE_POINTER , "Alias for ZPA (Zero Page Add)" },
{TEXT("ZP0") , CmdZeroPagePointer , CMD_ZEROPAGE_POINTER_0 , "Set/Update/Remove ZP watch 0 " },
{TEXT("ZP1") , CmdZeroPagePointer , CMD_ZEROPAGE_POINTER_1 , "Set/Update/Remove ZP watch 1" },
{TEXT("ZP2") , CmdZeroPagePointer , CMD_ZEROPAGE_POINTER_2 , "Set/Update/Remove ZP watch 2" },