From b952a5dde6517b7f99b4f8f2360187dbb5aa7bc5 Mon Sep 17 00:00:00 2001 From: AJR Date: Sun, 12 Feb 2023 19:00:40 -0500 Subject: validity.cpp: Be a bit more paranoid with null pointer checks; also disallow empty strings in BIOS definitions --- src/emu/validity.cpp | 54 ++++++++++++++++++++++++++++++++++--------------- src/mame/dec/jensen.cpp | 4 ++-- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/emu/validity.cpp b/src/emu/validity.cpp index ff5086bd8dd..831328cbb10 100644 --- a/src/emu/validity.cpp +++ b/src/emu/validity.cpp @@ -2151,28 +2151,38 @@ void validity_checker::validate_roms(device_t &root) int const bios_flags = ROM_GETBIOSFLAGS(romp); char const *const biosname = romp->name; if (bios_flags != last_bios + 1) - osd_printf_error("Non-sequential BIOS %s (specified as %d, expected to be %d)\n", biosname, bios_flags - 1, last_bios); + osd_printf_error("Non-sequential BIOS %s (specified as %d, expected to be %d)\n", biosname ? biosname : "UNNAMED", bios_flags - 1, last_bios); last_bios = bios_flags; // validate the name - if (strlen(biosname) > 16) - osd_printf_error("BIOS name %s exceeds maximum 16 characters\n", biosname); - for (char const *s = biosname; *s; ++s) + if (!biosname || biosname[0] == 0) + osd_printf_error("BIOS %d is missing a name\n", bios_flags - 1); + else { - if (((*s < '0') || (*s > '9')) && ((*s < 'a') || (*s > 'z')) && (*s != '.') && (*s != '_') && (*s != '-')) + if (strlen(biosname) > 16) + osd_printf_error("BIOS name %s exceeds maximum 16 characters\n", biosname); + for (char const *s = biosname; *s; ++s) { - osd_printf_error("BIOS name %s contains invalid characters\n", biosname); - break; + if (((*s < '0') || (*s > '9')) && ((*s < 'a') || (*s > 'z')) && (*s != '.') && (*s != '_') && (*s != '-')) + { + osd_printf_error("BIOS name %s contains invalid characters\n", biosname); + break; + } } - } - // check for duplicate names/descriptions - auto const nameins = bios_names.emplace(biosname, bios_flags); - if (!nameins.second) - osd_printf_error("Duplicate BIOS name %s specified (%d and %d)\n", biosname, nameins.first->second, bios_flags - 1); - auto const descins = bios_descs.emplace(romp->hashdata, biosname); - if (!descins.second) - osd_printf_error("BIOS %s has duplicate description '%s' (was %s)\n", biosname, romp->hashdata, descins.first->second); + // check for duplicate names/descriptions + auto const nameins = bios_names.emplace(biosname, bios_flags); + if (!nameins.second) + osd_printf_error("Duplicate BIOS name %s specified (%d and %d)\n", biosname, nameins.first->second, bios_flags - 1); + if (!romp->hashdata || romp->hashdata[0] == 0) + osd_printf_error("BIOS %s has empty description\n", biosname); + else + { + auto const descins = bios_descs.emplace(romp->hashdata, biosname); + if (!descins.second) + osd_printf_error("BIOS %s has duplicate description '%s' (was %s)\n", biosname, romp->hashdata, descins.first->second); + } + } } else if (ROMENTRY_ISDEFAULT_BIOS(romp)) // if this is a default BIOS setting, remember it so it to check at the end { @@ -2325,7 +2335,7 @@ void validity_checker::validate_dip_settings(const ioport_field &field) { char const *const demo_sounds = ioport_string_from_index(INPUT_STRING_Demo_Sounds); char const *const flipscreen = ioport_string_from_index(INPUT_STRING_Flip_Screen); - char const *const name = field.specific_name(); + char const *const name = field.specific_name() ? field.specific_name() : "UNNAMED"; u8 coin_list[__input_string_coinage_end + 1 - __input_string_coinage_start] = { 0 }; bool coin_error = false; @@ -2394,6 +2404,12 @@ void validity_checker::validate_dip_settings(const ioport_field &field) void validity_checker::validate_condition(const ioport_condition &condition, device_t &device) { + if (condition.tag() == nullptr) + { + osd_printf_error("Condition referencing null ioport tag\n"); + return; + } + // resolve the tag, then find a matching port if (m_ioport_set.find(device.subtag(condition.tag())) == m_ioport_set.end()) osd_printf_error("Condition referencing non-existent ioport tag '%s'\n", condition.tag()); @@ -2486,6 +2502,12 @@ void validity_checker::validate_inputs(device_t &root) if (field.specific_name() == nullptr) osd_printf_error("Config switch has no specific name\n"); } + else if (field.type() == IPT_ADJUSTER) + { + // adjuster fields must have a specific name + if (field.specific_name() == nullptr) + osd_printf_error("Adjuster has no specific name\n"); + } // verify names char const *const name = field.specific_name(); diff --git a/src/mame/dec/jensen.cpp b/src/mame/dec/jensen.cpp index 890705c03d2..ed8d09b26af 100644 --- a/src/mame/dec/jensen.cpp +++ b/src/mame/dec/jensen.cpp @@ -251,7 +251,7 @@ ROM_START(d2k300axp) ROM_LOAD("srom.bin", 0x00000, 0x2000, NO_DUMP) ROM_REGION32_LE(0x100000, "feprom1", 0) - ROM_SYSTEM_BIOS(0, "feprom", "") + ROM_SYSTEM_BIOS(0, "feprom", "Unknown version") ROMX_LOAD("feprom1.bin", 0x00000, 0x100000, NO_DUMP, ROM_BIOS(0)) ROM_END @@ -260,7 +260,7 @@ ROM_START(d2k500axp) ROM_LOAD("srom.bin", 0x00000, 0x2000, NO_DUMP) ROM_REGION32_LE(0x100000, "feprom1", 0) - ROM_SYSTEM_BIOS(0, "feprom", "") + ROM_SYSTEM_BIOS(0, "feprom", "Unknown version") ROMX_LOAD("feprom1.bin", 0x00000, 0x100000, NO_DUMP, ROM_BIOS(0)) ROM_END -- cgit v1.2.3