Tony Wasserka : d3dx9: Improve parameter validation in D3DXCreateFont and D3DXCreateFontIndirect.

Alexandre Julliard julliard at winehq.org
Wed Jun 24 09:22:56 CDT 2009


Module: wine
Branch: master
Commit: 823ec93b39373ddb9312157c9156aff636282f6a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=823ec93b39373ddb9312157c9156aff636282f6a

Author: Tony Wasserka <tony.wasserka at freenet.de>
Date:   Fri Jun  5 13:06:25 2009 +0200

d3dx9: Improve parameter validation in D3DXCreateFont and D3DXCreateFontIndirect.

---

 dlls/d3dx9_36/font.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/dlls/d3dx9_36/font.c b/dlls/d3dx9_36/font.c
index 46d0fde..e5e6569 100644
--- a/dlls/d3dx9_36/font.c
+++ b/dlls/d3dx9_36/font.c
@@ -194,7 +194,7 @@ HRESULT WINAPI D3DXCreateFontA(LPDIRECT3DDEVICE9 device, INT height, UINT width,
 {
     D3DXFONT_DESCA desc;
 
-    if(!facename) return D3DXERR_INVALIDDATA;
+    if( !device || !font ) return D3DERR_INVALIDCALL;
 
     desc.Height=height;
     desc.Width=width;
@@ -205,7 +205,8 @@ HRESULT WINAPI D3DXCreateFontA(LPDIRECT3DDEVICE9 device, INT height, UINT width,
     desc.OutputPrecision=precision;
     desc.Quality=quality;
     desc.PitchAndFamily=pitchandfamily;
-    lstrcpyA(desc.FaceName, facename);
+    if(facename != NULL) lstrcpyA(desc.FaceName, facename);
+    else desc.FaceName[0] = '\0';
 
     return D3DXCreateFontIndirectA(device, &desc, font);
 }
@@ -215,7 +216,7 @@ HRESULT WINAPI D3DXCreateFontW(LPDIRECT3DDEVICE9 device, INT height, UINT width,
 {
     D3DXFONT_DESCW desc;
 
-    if(!facename) return D3DXERR_INVALIDDATA;
+    if( !device || !font ) return D3DERR_INVALIDCALL;
 
     desc.Height=height;
     desc.Width=width;
@@ -226,7 +227,8 @@ HRESULT WINAPI D3DXCreateFontW(LPDIRECT3DDEVICE9 device, INT height, UINT width,
     desc.OutputPrecision=precision;
     desc.Quality=quality;
     desc.PitchAndFamily=pitchandfamily;
-    strcpyW(desc.FaceName, facename);
+    if(facename != NULL) strcpyW(desc.FaceName, facename);
+    else desc.FaceName[0] = '\0';
 
     return D3DXCreateFontIndirectW(device, &desc, font);
 }
@@ -238,8 +240,7 @@ HRESULT WINAPI D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_
 {
     D3DXFONT_DESCW widedesc;
 
-    if(!desc) return D3DERR_INVALIDCALL;
-    if(!desc->FaceName) return D3DERR_INVALIDCALL;
+    if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
 
     /* Copy everything but the last structure member. This requires the
        two D3DXFONT_DESC structures to be equal until the FaceName member */
@@ -254,11 +255,25 @@ HRESULT WINAPI D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_
  */
 HRESULT WINAPI D3DXCreateFontIndirectW(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCW *desc, LPD3DXFONT *font)
 {
+    D3DDEVICE_CREATION_PARAMETERS cpars;
+    D3DDISPLAYMODE mode;
     ID3DXFontImpl *object;
-
+    IDirect3D9 *d3d;
+    HRESULT hr;
     FIXME("stub\n");
 
-    if(!desc) return D3DERR_INVALIDCALL;
+    if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
+
+    /* the device MUST support D3DFMT_A8R8G8B8 */
+    IDirect3DDevice9_GetDirect3D(device, &d3d);
+    IDirect3DDevice9_GetCreationParameters(device, &cpars);
+    IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
+    hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
+    if(FAILED(hr)) {
+        IDirect3D9_Release(d3d);
+        return D3DXERR_INVALIDDATA;
+    }
+    IDirect3D9_Release(d3d);
 
     object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXFontImpl));
     if(object==NULL) {




More information about the wine-cvs mailing list