Added negative index protections into GetCHRAddress to protect against a large unsigned number being passed and interpretted as a negative number. Caught by gcc UBSAN.

This commit is contained in:
harry 2023-01-10 17:42:45 -05:00
parent 293fc7b672
commit 4dd8943724
1 changed files with 16 additions and 5 deletions

View File

@ -456,13 +456,24 @@ volatile int rendercount, vromreadcount, undefinedvromcount, LogAddress = -1;
unsigned char *cdloggervdata = NULL;
unsigned int cdloggerVideoDataSize = 0;
int GetCHRAddress(int A) {
if (cdloggerVideoDataSize) {
int result = &VPage[A >> 10][A] - CHRptr[0];
int GetCHRAddress(int A)
{
if (cdloggerVideoDataSize)
{
int result = -1;
if ( (A >= 0) && (A < 0x2000) )
{
result = &VPage[A >> 10][A] - CHRptr[0];
}
if ((result >= 0) && (result < (int)cdloggerVideoDataSize))
{
return result;
} else
if(A < 0x2000) return A;
}
}
else
{
if ( (A >= 0) && (A < 0x2000) ) return A;
}
return -1;
}