Module: wine Branch: refs/heads/master Commit: b06a06090a91a136a7cdd10dd36dbbb149d81a0a URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=b06a06090a91a136a7cdd10d...
Author: Robert Reif reif@earthlink.net Date: Fri Apr 28 23:40:09 2006 -0400
dsound: Check DirectSoundBuffer_Lock parameters.
Check DirectSoundBuffer_Lock parameters and return an error (like Windows) rather than fixing up the parameters.
---
dlls/dsound/buffer.c | 23 +++++++++++++++++------ dlls/dsound/primary.c | 26 +++++++++++++++++--------- 2 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c index 1470f84..68c6169 100644 --- a/dlls/dsound/buffer.c +++ b/dlls/dsound/buffer.c @@ -567,21 +567,31 @@ static HRESULT WINAPI IDirectSoundBuffer GetTickCount() );
+ /* when this flag is set, writecursor is meaningless and must be calculated */ if (flags & DSBLOCK_FROMWRITECURSOR) { - DWORD writepos; /* GetCurrentPosition does too much magic to duplicate here */ - hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writepos); + hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writecursor); if (hres != DS_OK) { WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n"); return hres; } - writecursor += writepos; } - writecursor %= This->buflen; + + /* when this flag is set, writebytes is meaningless and must be set */ if (flags & DSBLOCK_ENTIREBUFFER) writebytes = This->buflen; - if (writebytes > This->buflen) - writebytes = This->buflen; + + if (writecursor >= This->buflen) { + WARN("Invalid parameter, writecursor: %lu >= buflen: %lu\n", + writecursor, This->buflen); + return DSERR_INVALIDPARAM; + } + + if (writebytes > This->buflen) { + WARN("Invalid parameter, writebytes: %lu > buflen: %lu\n", + writebytes, This->buflen); + return DSERR_INVALIDPARAM; + }
EnterCriticalSection(&(This->lock));
@@ -648,6 +658,7 @@ static HRESULT WINAPI IDirectSoundBuffer }
LeaveCriticalSection(&(This->lock)); + return DS_OK; }
diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index e3cd3a2..304e962 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -665,6 +665,7 @@ static HRESULT WINAPI PrimaryBufferImpl_ static HRESULT WINAPI PrimaryBufferImpl_Lock( LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags ) { + HRESULT hres; DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device; TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n", iface, @@ -683,26 +684,33 @@ static HRESULT WINAPI PrimaryBufferImpl_ return DSERR_PRIOLEVELNEEDED; }
+ /* when this flag is set, writecursor is meaningless and must be calculated */ if (flags & DSBLOCK_FROMWRITECURSOR) { - DWORD writepos; - HRESULT hres; /* GetCurrentPosition does too much magic to duplicate here */ - hres = IDirectSoundBuffer_GetCurrentPosition(iface, NULL, &writepos); + hres = IDirectSoundBuffer_GetCurrentPosition(iface, NULL, &writecursor); if (hres != DS_OK) { WARN("IDirectSoundBuffer_GetCurrentPosition failed\n"); return hres; } - writecursor += writepos; } - while (writecursor >= device->buflen) - writecursor -= device->buflen; + + /* when this flag is set, writebytes is meaningless and must be set */ if (flags & DSBLOCK_ENTIREBUFFER) writebytes = device->buflen; - if (writebytes > device->buflen) - writebytes = device->buflen; + + if (writecursor >= device->buflen) { + WARN("Invalid parameter, writecursor: %lu >= buflen: %lu\n", + writecursor, device->buflen); + return DSERR_INVALIDPARAM; + } + + if (writebytes > device->buflen) { + WARN("Invalid parameter, writebytes: %lu > buflen: %lu\n", + writebytes, device->buflen); + return DSERR_INVALIDPARAM; + }
if (!(device->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK) && device->hwbuf) { - HRESULT hres; hres = IDsDriverBuffer_Lock(device->hwbuf, lplpaudioptr1, audiobytes1, lplpaudioptr2, audiobytes2,