aboutsummaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
authorJohannes Schickel2015-05-20 00:19:01 +0200
committerMatthew Hoops2015-07-07 20:19:41 -0400
commit6f01600e12ba14acde8a6557716783861dc014d1 (patch)
tree2a32a7d5e9e7abc7236d1898e6606aa7c34bdff8 /audio
parent47aa40104d11d92ea3c53390851e719d133fc7b9 (diff)
downloadscummvm-rg350-6f01600e12ba14acde8a6557716783861dc014d1.tar.gz
scummvm-rg350-6f01600e12ba14acde8a6557716783861dc014d1.tar.bz2
scummvm-rg350-6f01600e12ba14acde8a6557716783861dc014d1.zip
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.
Diffstat (limited to 'audio')
-rw-r--r--audio/fmopl.cpp14
-rw-r--r--audio/fmopl.h6
2 files changed, 19 insertions, 1 deletions
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
diff --git a/audio/fmopl.h b/audio/fmopl.h
index 85ac606c7a..28dd456e21 100644
--- a/audio/fmopl.h
+++ b/audio/fmopl.h
@@ -71,6 +71,12 @@ public:
static DriverId parse(const Common::String &name);
/**
+ * @return The driver description for the given id or 0 in case it is not
+ * available.
+ */
+ static const EmulatorDescription *findDriver(DriverId id);
+
+ /**
* Detects a driver for the specific type.
*
* @return Returns a valid driver id on success, -1 otherwise.