Huw Davies : gdi32: Zero pad the facename buffer so that we don' t write uninitialized data to the metafile.

Alexandre Julliard julliard at winehq.org
Wed Feb 3 09:33:08 CST 2010


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

Author: Huw Davies <huw at codeweavers.com>
Date:   Wed Feb  3 14:33:06 2010 +0000

gdi32: Zero pad the facename buffer so that we don't write uninitialized data to the metafile.

Found by Valgrind.

---

 dlls/gdi32/mfdrv/objects.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/dlls/gdi32/mfdrv/objects.c b/dlls/gdi32/mfdrv/objects.c
index a7a442b..c6a68ca 100644
--- a/dlls/gdi32/mfdrv/objects.c
+++ b/dlls/gdi32/mfdrv/objects.c
@@ -365,6 +365,7 @@ static UINT16 MFDRV_CreateFontIndirect(PHYSDEV dev, HFONT hFont, LOGFONTW *logfo
     char buffer[sizeof(METARECORD) - 2 + sizeof(LOGFONT16)];
     METARECORD *mr = (METARECORD *)&buffer;
     LOGFONT16 *font16;
+    INT written;
 
     mr->rdSize = (sizeof(METARECORD) + sizeof(LOGFONT16) - 2) / 2;
     mr->rdFunction = META_CREATEFONTINDIRECT;
@@ -383,8 +384,9 @@ static UINT16 MFDRV_CreateFontIndirect(PHYSDEV dev, HFONT hFont, LOGFONTW *logfo
     font16->lfClipPrecision  = logfont->lfClipPrecision;
     font16->lfQuality        = logfont->lfQuality;
     font16->lfPitchAndFamily = logfont->lfPitchAndFamily;
-    WideCharToMultiByte( CP_ACP, 0, logfont->lfFaceName, -1, font16->lfFaceName, LF_FACESIZE, NULL, NULL );
-    font16->lfFaceName[LF_FACESIZE-1] = 0;
+    written = WideCharToMultiByte( CP_ACP, 0, logfont->lfFaceName, -1, font16->lfFaceName, LF_FACESIZE - 1, NULL, NULL );
+    /* Zero pad the facename buffer, so that we don't write uninitialized data to disk */
+    memset(font16->lfFaceName + written, 0, LF_FACESIZE - written);
 
     if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * 2)))
         return 0;




More information about the wine-cvs mailing list