From c1069f559b52a5e4e4ce0a683ca6b130aefab27d Mon Sep 17 00:00:00 2001 From: Stian Skjelstad Date: Tue, 30 Jul 2024 23:58:21 +0200 Subject: [PATCH] Attempting to load a defective S3M file could trigger two different issues (Fixes #118) * Do not call mcpSet() on close, as it might not be set up if loading failed. Trust the wavetable driver to reset itself. * que variable was not reset to NULL after free(), causing a double free. --- playgmd/gmdls3m.c | 9 +++++++-- playgmd/gmdplay.c | 6 +----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/playgmd/gmdls3m.c b/playgmd/gmdls3m.c index 88770cab..52b62ad9 100644 --- a/playgmd/gmdls3m.c +++ b/playgmd/gmdls3m.c @@ -100,9 +100,14 @@ OCP_INTERNAL int LoadS3M (struct cpifaceSessionAPI_t *cpifaceSession, struct gmd cpifaceSession->cpiDebug (cpifaceSession, "[GMD/S3M] Invalid signature\n"); return errFormSig; } - if ((hdr.orders>255)||(hdr.pats>=254)) + if (hdr.orders>255) { - cpifaceSession->cpiDebug (cpifaceSession, "[GMD/S3M] too many orders and/or patterns\n"); + cpifaceSession->cpiDebug (cpifaceSession, "[GMD/S3M] too many orders (0x%04x > 0x00ff)\n", hdr.orders); + return errFormStruc; + } + if (hdr.pats>=254) + { + cpifaceSession->cpiDebug (cpifaceSession, "[GMD/S3M] too many patterns (0x%04x >= 0x00fe)\n", hdr.pats); return errFormStruc; } diff --git a/playgmd/gmdplay.c b/playgmd/gmdplay.c index cffe0574..be189ccb 100644 --- a/playgmd/gmdplay.c +++ b/playgmd/gmdplay.c @@ -1647,13 +1647,9 @@ OCP_INTERNAL int mpPlayModule (const struct gmdmodule *m, struct ocpfilehandle_t OCP_INTERNAL void mpStopModule (struct cpifaceSessionAPI_t *cpifaceSession) { - int i; - for (i=0; imcpSet (cpifaceSession, i, mcpCReset, 0); - } cpifaceSession->mcpDevAPI->ClosePlayer (cpifaceSession); free(que); + que=0; } OCP_INTERNAL void mpGetChanInfo (uint8_t ch, struct chaninfo *ci)