From 6f01600e12ba14acde8a6557716783861dc014d1 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 20 May 2015 00:19:01 +0200 Subject: AUDIO: Fix abuse of driver IDs in OPL code. If the driver id did not match the array index, the wrong driver entry would be accessed causing a crash in the worst case. --- audio/fmopl.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'audio/fmopl.cpp') diff --git a/audio/fmopl.cpp b/audio/fmopl.cpp index 30229ea6bf..00e49ef598 100644 --- a/audio/fmopl.cpp +++ b/audio/fmopl.cpp @@ -63,6 +63,15 @@ Config::DriverId Config::parse(const Common::String &name) { return -1; } +const Config::EmulatorDescription *Config::findDriver(DriverId id) { + for (int i = 0; _drivers[i].name; ++i) { + if (_drivers[i].id == id) + return &_drivers[i]; + } + + return 0; +} + Config::DriverId Config::detect(OplType type) { uint32 flags = 0; switch (type) { @@ -90,8 +99,11 @@ Config::DriverId Config::detect(OplType type) { // When a valid driver is selected, check whether it supports // the requested OPL chip. if (drv != -1 && drv != kAuto) { + const EmulatorDescription *driverDesc = findDriver(drv); // If the chip is supported, just use the driver. - if ((flags & _drivers[drv].flags)) { + if (!driverDesc) { + warning("The selected OPL driver %d could not be found", drv); + } else if ((flags & driverDesc->flags)) { return drv; } else { // Else we will output a warning and just -- cgit v1.2.3