From 321189aa21535cb13f1d579327f867360efcb1a8 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 10 May 2004 19:56:53 +0000 Subject: [PATCH] More parameter checking fixes with tests. --- dlls/msacm/format.c | 18 +++++++++++++- dlls/msacm/pcmconverter.c | 2 +- dlls/msacm/tests/msacm.c | 50 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/dlls/msacm/format.c b/dlls/msacm/format.c index 7a116ba3535..b64f8b0db5d 100644 --- a/dlls/msacm/format.c +++ b/dlls/msacm/format.c @@ -741,6 +741,15 @@ MMRESULT WINAPI acmFormatTagEnumA(HACMDRIVER had, PACMFORMATTAGDETAILSA paftda, ACMFORMATTAGDETAILSW aftdw; struct MSACM_FormatTagEnumWtoA_Instance aftei; + if (!paftda) + return MMSYSERR_INVALPARAM; + + if (paftda->cbStruct < sizeof(*paftda)) + return MMSYSERR_INVALPARAM; + + if (fdwEnum != 0) + return MMSYSERR_INVALFLAG; + memset(&aftdw, 0, sizeof(aftdw)); aftdw.cbStruct = sizeof(aftdw); aftdw.dwFormatTagIndex = paftda->dwFormatTagIndex; @@ -768,7 +777,14 @@ MMRESULT WINAPI acmFormatTagEnumW(HACMDRIVER had, PACMFORMATTAGDETAILSW paftd, TRACE("(%p, %p, %p, %ld, %ld)\n", had, paftd, fnCallback, dwInstance, fdwEnum); - if (paftd->cbStruct < sizeof(*paftd)) return MMSYSERR_INVALPARAM; + if (!paftd) + return MMSYSERR_INVALPARAM; + + if (paftd->cbStruct < sizeof(*paftd)) + return MMSYSERR_INVALPARAM; + + if (fdwEnum != 0) + return MMSYSERR_INVALFLAG; /* (WS) MSDN info page says that if had != 0, then we should find * the specific driver to get its tags from. Therefore I'm removing diff --git a/dlls/msacm/pcmconverter.c b/dlls/msacm/pcmconverter.c index 30c64a1bf21..3f335d005ce 100644 --- a/dlls/msacm/pcmconverter.c +++ b/dlls/msacm/pcmconverter.c @@ -960,7 +960,7 @@ static LRESULT PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs) if (adfs->pwfxSrc->wFormatTag != WAVE_FORMAT_PCM) { WARN("not possible\n"); return ACMERR_NOTPOSSIBLE; - } + } adfs->pwfxDst->wFormatTag = adfs->pwfxSrc->wFormatTag; } /* check if result is ok */ diff --git a/dlls/msacm/tests/msacm.c b/dlls/msacm/tests/msacm.c index 84879ca5882..63057b5ffde 100644 --- a/dlls/msacm/tests/msacm.c +++ b/dlls/msacm/tests/msacm.c @@ -31,6 +31,16 @@ #include "mmreg.h" #include "msacm.h" +static BOOL CALLBACK FormatTagEnumProc(HACMDRIVERID hadid, + PACMFORMATTAGDETAILS paftd, + DWORD dwInstance, + DWORD fdwSupport) +{ + trace(" Format 0x%04lx: %s\n", paftd->dwFormatTag, paftd->szFormatTag); + + return TRUE; +} + static BOOL CALLBACK FormatEnumProc(HACMDRIVERID hadid, LPACMFORMATDETAILS pafd, DWORD dwInstance, @@ -141,8 +151,6 @@ static BOOL CALLBACK DriverEnumProc(HACMDRIVERID hadid, if (rc == MMSYSERR_NOERROR) { DWORD dwSize; - WAVEFORMATEX * pwfx; - ACMFORMATDETAILS fd; HACMDRIVERID hid; /* try bad pointer */ @@ -202,6 +210,10 @@ static BOOL CALLBACK DriverEnumProc(HACMDRIVERID hadid, "acmMetrics(): rc = %08x, should be %08x\n", rc, MMSYSERR_NOERROR); if (rc == MMSYSERR_NOERROR) { + ACMFORMATDETAILS fd; + WAVEFORMATEX * pwfx; + ACMFORMATTAGDETAILS aftd; + /* try bad pointer */ rc = acmFormatEnum(had, 0, FormatEnumProc, 0, 0); ok(rc == MMSYSERR_INVALPARAM, @@ -241,6 +253,40 @@ static BOOL CALLBACK DriverEnumProc(HACMDRIVERID hadid, "acmFormatEnum(): rc = %08x, should be %08x\n", rc, MMSYSERR_NOERROR); + /* try bad pointer */ + rc = acmFormatTagEnum(had, 0, FormatTagEnumProc, 0, 0); + ok(rc == MMSYSERR_INVALPARAM, + "acmFormatTagEnum(): rc = %08x, should be %08x\n", + rc, MMSYSERR_INVALPARAM); + + /* try bad structure size */ + ZeroMemory(&aftd, sizeof(fd)); + rc = acmFormatTagEnum(had, &aftd, FormatTagEnumProc, 0, 0); + ok(rc == MMSYSERR_INVALPARAM, + "acmFormatTagEnum(): rc = %08x, should be %08x\n", + rc, MMSYSERR_INVALPARAM); + + aftd.cbStruct = sizeof(aftd) - 1; + rc = acmFormatTagEnum(had, &aftd, FormatTagEnumProc, 0, 0); + ok(rc == MMSYSERR_INVALPARAM, + "acmFormatTagEnum(): rc = %08x, should be %08x\n", + rc, MMSYSERR_INVALPARAM); + + aftd.cbStruct = sizeof(aftd); + aftd.dwFormatTag = WAVE_FORMAT_UNKNOWN; + + /* try bad flag */ + rc = acmFormatTagEnum(had, &aftd, FormatTagEnumProc, 0, 1); + ok(rc == MMSYSERR_INVALFLAG, + "acmFormatTagEnum(): rc = %08x, should be %08x\n", + rc, MMSYSERR_INVALFLAG); + + /* try valid parameters */ + rc = acmFormatTagEnum(had, &aftd, FormatTagEnumProc, 0, 0); + ok(rc == MMSYSERR_NOERROR, + "acmFormatTagEnum(): rc = %08x, should be %08x\n", + rc, MMSYSERR_NOERROR); + free(pwfx); /* try invalid handle */