From b7f56efccce8f5eeb995bb35fefa4979d414d033 Mon Sep 17 00:00:00 2001 From: OV2 Date: Tue, 14 Mar 2023 12:26:44 +0100 Subject: [PATCH] Ensure ROMId is safe --- memmap.cpp | 18 ++++++++++++++++++ memmap.h | 1 + 2 files changed, 19 insertions(+) diff --git a/memmap.cpp b/memmap.cpp index 880e6338..f4441ef9 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -2424,6 +2424,7 @@ void CMemory::InitROM (void) //// Show ROM information ROMId[4] = 0; + strcpy(ROMId, SafeString(ROMId).c_str()); sprintf(String, "\"%s\" [%s] %s, %s, %s, %s, SRAM:%s, ID:%s, CRC32:%08X", ROMName, isChecksumOK ? "checksum ok" : ((Multi.cartType == 4) ? "no checksum" : "bad checksum"), @@ -3500,6 +3501,23 @@ void CMemory::ApplyROMFixes (void) Timings.RenderPos = 32; } +std::string CMemory::SafeString(std::string s, bool allow_jis /*=false*/) +{ + std::string safe; + for (int i = 0; i < s.length(); i++) + { + if (s[i] >= 32 && s[i] < 127) // ASCII + safe += s[i]; + else + if (allow_jis && ROMRegion == 0 && ((uint8)s[i] >= 0xa0 && (uint8)s[i] < 0xe0)) // JIS X 201 - Katakana + safe += s[i]; + else + safe += '_'; + } + + return safe; +} + // BPS % UPS % IPS // number decoding used for both BPS and UPS diff --git a/memmap.h b/memmap.h index d0818559..dde0c7d1 100644 --- a/memmap.h +++ b/memmap.h @@ -170,6 +170,7 @@ struct CMemory bool8 match_nc (const char *); bool8 match_id (const char *); void ApplyROMFixes (void); + std::string SafeString(std::string s, bool allow_jis = false); void CheckForAnyPatch (const char *, bool8, int32 &); void MakeRomInfoText (char *);